Sharp Arch with Rhino Security

16 views
Skip to first unread message

Kevin Amerson

unread,
Nov 15, 2009, 8:39:01 PM11/15/09
to sharp-arc...@googlegroups.com
I found the email below, but am having an issue that I'm struggling with.

When I try to inject a Rhino Security service / repository, I get this error:

Type NHibernate.ISession is abstract.
As such, it is not possible to instansiate it as implementation of NHibernate.ISession service

Thoughts?  I did register the ISession using factory method as stated below.

---


On Sep 10, 8:52 am, David Archer <darc...@gmail.com> wrote:
> Hello everyone,
>
> I recently undertook integrating the latest Rhino.Security bits into
> my project and there were a few pain points:
>
> 1) Rhino.Security wants to be able to pull the current ISession using
> the ServiceLocator but this isn't supported out of the box by Sharp. I
> ended up adding it to Windsor in the ComponentRegistrar.cs class in
> the MyProject.Web project using something like this:
>
>         private static void AddRhinoSecurityComponentsTo
> (IWindsorContainer container)
>         {
>             container.Kernel.Register(
>                 // All the other stuff that Rhino Security needs
> registered in the container
>                 Component.For<ISession>()
>                     .UsingFactoryMethod(() =>
> NHibernateSession.Current)
>                     .LifeStyle.Is(LifestyleType.Transient)
>                 );
>         }
>
> The trouble I ran into initially is that the WebSessionStorage and
> Windsor are both out-of-the-box trying to Dispose/Close the ISession
> at the end of the request. This ended up giving me an exception
> "Session is already closed" since Windsor would Dispose/Close the
> ISession and then the WebSessionStorage would try to do the same. The
> fix was to create a custom WebSessionStorage that only closes the
> session if it is open:
>
>         private void Application_EndRequest(object sender, EventArgs
> e)
>         {
>             ISession session = Session;
>
>             if (session != null)
>             {
>                 // The only changed line is below this comment :)
>                 if (session.IsOpen) session.Close();
>                 HttpContext context = HttpContext.Current;
>                 context.Items.Remove(factoryKey);
>             }
>         }
>
> This works and resolves the issue. Anyone see any gotchas here or
> reasons this can't be integrated into trunk?
>
> 2) Rhino Security needs access to the NHibernate Configuration object
> after it is created but before the Session Factory is built. Luckily,
> there is a way to do this but I'm not sure that this is the right way.
> I saw that the NHibernateSession.Init() function has an overload that
> takes in a FluentNHibernate.Cfg.Db.IPersistenceConfigurer and that
> object gets passed the NHibernate configuration at the correct time
> during the initialization process. I ended up creating a
> RhinoSecurityPersistenceConfigurer class like so:
>
> using MyProject.Core;
> using FluentNHibernate.Cfg.Db;
> using NHibernate.Cfg;
> using Rhino.Security;
>
> namespace MyProject.Web.CastleWindsor
> {
>     public class RhinoSecurityPersistenceConfigurer :
> IPersistenceConfigurer
>     {
>         public Configuration ConfigureProperties(Configuration
> nhibernateConfig)
>         {
>             Security.Configure<User>(nhibernateConfig,
> SecurityTableStructure.Prefix);
>
>             return nhibernateConfig;
>         }
>     }
>
> }
>
> and I changed the call to NHIbernate.Init() in global.asax.cs to:
>
>             var config = NHibernateSession.Init(
>                 webSessionStorage,
>                 new[] { Server.MapPath("~/bin/MyProject.Data.dll") },
>                 new AutoPersistenceModelGenerator().Generate(),
>                 Server.MapPath("~/NHibernate.config"),
>                 null, null, new RhinoSecurityPersistenceConfigurer());
>
> I'm really not sure if this is the "right way" to do this but there
> didn't seem to be any other facility in Sharp to be able to access the
> NHibernate Configuration object prior to the Session Factory being
> created. Technically, it _is_ "configuring the persistence" for Rhino
> Security (setting up object mappings and tables and such) so I don't
> think it's too much of a hack.
>
> Hope this helps anyone trying to get the latest Rhino.Security working
> with Sharp. Please let me know if you see any issues in getting the
> change from #1 rolled into trunk.
>
> Thanks,
>
> David Archer

Bassie

unread,
Dec 21, 2009, 1:39:04 PM12/21/09
to S#arp Architecture
I also get this error message when trying to get rhino security
working.

"Type NHibernate.ISession is abstract. As such, it is not possible to
instansiate it as implementation of NHibernate.ISession service"

this is the code i use in ComponentRegistrar.cs


Component.For<ISession>()
.UsingFactoryMethod(() =>
NHibernateSession.Current)
.LifeStyle.Is(LifestyleType.Transient)
);

any suggestions?

On 16 nov, 02:39, Kevin Amerson <kevin.amer...@gmail.com> wrote:
> I found the email below, but am having an issue that I'm struggling with.
>
> When I try to inject a Rhino Security service / repository, I get this
> error:
>

> *Type NHibernate.ISession is abstract.


> As such, it is not possible to instansiate it as implementation of

> NHibernate.ISession service* Thoughts?  I did register the ISession using

Bassie

unread,
Dec 21, 2009, 2:16:51 PM12/21/09
to S#arp Architecture

Bassie

unread,
Dec 28, 2009, 4:24:06 PM12/28/09
to S#arp Architecture
problem is solved after reading this post of david archer
http://groups.google.nl/group/sharp-architecture/browse_thread/thread/3de5b3ac93febbe0
i forgot to register the FactorySupportFacility

// sample code:
container.AddFacility<FactorySupportFacility>()
.Register(Component.For<ISession>()
.UsingFactoryMethod(() => NHibernateSession.Current)
.LifeStyle.Is(LifestyleType.Transient));

Reply all
Reply to author
Forward
0 new messages