I like that too :)

On Sep 18, 11:46 am, Valeriu Caraulean <[email protected]> wrote:
> Shorter version to register an ISession in container and provide it using
> ISessionFactory:
>
> container.Register(
> Component
>    .For<ISession>()
>    .LifeStyle.Transient
>    .UsingFactoryMethod(() =>
> container.Resolve<ISessionFactory>().GetCurrentSession());
>
> Cheers :)
>
> On Fri, Sep 18, 2009 at 5:23 PM, Jason Meckley <[email protected]>wrote:
>
>
>
> > I inject a session as a ctor dependency like this
>
> > class Service
> > {
> >       private readonly ISession session;
> >       public Service(ISession session)
> >       {
> >            this.session = session;
> >       }
>
> >       public void DoWork(int id)
> >       {
> >            var entity = session.Load<Entity>(id);
> >            session.Delete(entity)
> >       }
> > }
>
> > class SessionResolver : ISubDependencyResolver
> > {
> >      private readonly ISessionFactory factory;
> >      public SessionResolver(ISessionFactory factory)
> >      {
> >            this.factory = factory;
> >      }
>
> >      public object Resolve(...)
> >      {
> >           return new SessionAdapter(factory);
> >      }
>
> >      public bool CanResolve(...)
> >      {
> >           return typeof(ISession).IsAssignableFrom
> > (dependency.TargetType);
> >      }
> > }
>
> > class SessionAdapter : ISession
> > {
> >      private readonly ISessionFactory factory;
> >      public SessionAdapter(ISessionFactory factory)
> >      {
> >            this.factory = factory;
> >      }
>
> >      private ISession session { get { return factory.GetCurrentSession
> > (); } }
>
> >      private T Load<T>(object id)
> >      {
> >           return session.Load<T>(id);
> >      }
>
> >      private Delete(object entity)
> >      {
> >           return session.Delete(entity);
> >      }
>
> >      //the rest of the ISession members...
> > }
>
> > On Sep 18, 9:25 am, Martin Nilsson <[email protected]> wrote:
> > > How does your repositories looks like? Because you can't take the
> > dependency
> > > to ISession as a ctor? I'm replacing Rhino Commons with plain session
> > > management but I'm not sure how to interact between my services and
> > > repositories. Can you give a brief example. Something like this
>
> > > ProductService:
> > > public void Save(Product product) {
> > >   using(var session = ?.GetSession)
> > >   using(var tx = session.BeginTransaction())
> > >   {
> > >     repository.Add(product);
> > >     tx.Commit();
> > >   }
>
> > > }
>
> > > ProductRepository:
> > > public void Add(Product product) {
> > >    session.SaveOrUpdate(product);
>
> > > }
>
> > > Does your repository have a dependency to IKernel maybe?
>
> > > On Thu, Sep 10, 2009 at 8:35 PM, Ayende Rahien <[email protected]>
> > wrote:
> > > > I am talking about something like:
>
> > > > kernel.Register(  Component.For<ISession>()
> > > >      .FactoryMethod( () => HttpContext.Items["current-session"]) )
> > > > );
>
> > > > On Thu, Sep 10, 2009 at 9:33 PM, Tyler Burd <[email protected]>
> > wrote:
>
> > > >> When you say "ambient session from the container", do you mean
> > actually
> > > >> injecting the ISession?  Do you accomplish this via child containers
> > when
> > > >> needing a session-per-web-request or something similar?  Or do you use
> > a
> > > >> per-web-request life-cycle when you register ISession with the
> > container?
>
> > > >> On Thu, Sep 10, 2009 at 12:20 PM, Ayende Rahien <[email protected]
> > >wrote:
>
> > > >>> Yes, that is a good scenario for Binsor.But it is actually not
> > something
> > > >>> that I tend to do
>
> > > >>> On Thu, Sep 10, 2009 at 9:06 PM, Nathan Stott <[email protected]>
> > wrote:
>
> > > >>>> I disagree.  Binsor, on several occasions, has saved me a lot of
> > > >>>> headache by allowing me to reconfigure my apps in production without
> > having
> > > >>>> to recompile them.  Windsor Fl does not allow for this.
>
> > > >>>> On Thu, Sep 10, 2009 at 2:02 PM, Ayende Rahien <[email protected]
> > >wrote:
>
> > > >>>>> To be absolutely honest, with the Windsor FI, I am not sure there
> > is a
> > > >>>>> lot of place for Binsor.
>
> > > >>>>> On Thu, Sep 10, 2009 at 8:59 PM, rg <[email protected]>
> > wrote:
>
> > > >>>>>> Please save the Binsor!
> > > >>>>>> R
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino Tools Dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rhino-tools-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to