Castle | NHibernate Session Management | Windows Service

174 views
Skip to first unread message

Mike

unread,
Aug 14, 2012, 2:33:06 PM8/14/12
to castle-pro...@googlegroups.com

 Hi,

I have got a windows service which looks for a certain file and save it to the DB. I'm using the repository pattern and using Castle Windsor for DI.

This is how I register the NHibernate ISession and my unit of work.

 container.Register(
           
Component.For<ISession>().UsingFactoryMethod(() => NHibernateSessionManager.Instance.GetSession()).LifeStyle.Transient);

            container
.Register(
               
Component.For<INHibernateSessionManager>().Instance(NHibernateSessionManager.Instance).LifestyleSingleton());

            container
.Register(
               
Component.For<IUnitOfWork<ISession>>().ImplementedBy<Data.Framework.Nhibernate.UnitOfWork.NHibernateUnitOfWork>().LifeStyle.Transient);

            container
.Register(Component.For(typeof(IRepository<>)).ImplementedBy(typeof(NHibernateRepository<>)).LifeStyle.Transient);

This does not work for me, as when it tried to resolve the repository it's complaining about a key added to the repository already.

Can you please tell me how to do this properly?

Thanks, -Mike

Henrik

unread,
Aug 22, 2012, 6:50:29 PM8/22/12
to castle-pro...@googlegroups.com
This might help:
https://github.com/haf/Castle.Facilities.NHibernate/blob/master/src/Castle.Facilities.NHibernate/NHibernateFacility.cs#L257


On Tuesday, August 14, 2012 8:33:06 PM UTC+2, Mike wrote:

 Hi,

I have got a windpows service which looks for a certain file and save it to the DB. I'm using the repository pattern and using Castle Windsor for DI.

Reply all
Reply to author
Forward
0 new messages