Reputation: 53991
Using Castle Windsor as my IoC container and NHibernate I have the following registration:
Component.For<ICustomSessionFactory>()
.ImplementedBy<MsSql2008SessionFactory>().LifeStyle.Singleton,
Component.For<ISession>()
.UsingFactoryMethod(kernel => kernel.Resolve<ICustomSessionFactory>()
.OpenSession()).LifeStyle.PerWebRequest,
Where ISession
is an NHibernate.ISession
.
This works great. My question is regarding the closing of my ISession
.
Will Castle Windsor deal with the closing of my session or do I need to close it myself some how?
I see in the documentation that:
Therefore Windsor knows when to release the per web request objects and it will do it without requiring any action from you.
Does this mean that the closing of the session is handled by default?
Upvotes: 0
Views: 528
Reputation: 18909
Yeah, windsor will close the session for you.
You can also log all the container info:
void ConfigureContainer()
{
_container = new WindsorContainer();
_container.Install(new LoggerInstaller());
_logger = _container.Resolve<ILogger>();
#if DEBUG
_container.Kernel.ComponentRegistered += (k, h) => _logger.Debug(String.Format("Registered {0} - {1}/{2}", k, h.ComponentModel.ComponentName.Name, h.ComponentModel.Implementation.FullName));
_container.Kernel.ComponentDestroyed += (k, h) => _logger.Debug(String.Format("Destoyed {0} - ", k.ComponentName.Name));
#endif
_container.Install(new ContainerInstaller());
_container.Install(new NHibernateInstaller());
_container.Install(new ValidationInstaller());
}
Upvotes: 1