There is some other related issue i encountered and i thought I'd
share.
When you use transient components in combination with castle and one
your transient component has a dependency on a component that is
IDisposable, you should make sure to call IKernel.ReleaseComponent().
If you don't, you will be leaking memory in the form of
Castle.MicroKernel.Burden objects (the componet burden tracking
subsystem ).
Now ISession does extend IDisposable, hence this leak actually happens
when you are using this factory method.
Now you don't want MicroKernel to be calling Dispose on your ISession
either, since you are managing the ISession using Rhino.Commons, and
its the responsibility of NHibernateUnitOfWorkFactory to Disponse the
session.
I eventually solved the problem by plugging in my own
ComponentModelBuilder into MicroKernel, which in turn uses a custom
LifecycleModelInspector (LifecycleModelInspectorThatIgnoresISession)
that does not add a Decommission LifecycleStepType for ISession. (And
hence disables the burden tracking for ISession)
public class LifecycleModelInspectorThatIgnoresISession :
LifecycleModelInspector
{
public override void ProcessModel(IKernel kernel,
Castle.Core.ComponentModel model)
{
if (model == null)
{
throw new ArgumentNullException("model");
}
if (typeof(IInitializable).IsAssignableFrom
(model.Implementation))
{
model.LifecycleSteps.Add
(LifecycleStepType.Commission, InitializationConcern.Instance);
}
if (typeof(ISupportInitialize).IsAssignableFrom
(model.Implementation))
{
model.LifecycleSteps.Add
(LifecycleStepType.Commission, SupportInitializeConcern.Instance);
}
if (typeof(IDisposable).IsAssignableFrom
(model.Implementation)
&& !typeof(ISession).IsAssignableFrom
(model.Implementation)) //Session specific
{
model.LifecycleSteps.Add
(LifecycleStepType.Decommission, DisposalConcern.Instance);
}
}
}
}
There may be more elegant ways though...
-Tom
On Nov 25, 3:08 pm, Jason Meckley <
jasonmeck...@gmail.com> wrote:
> chris, you can also configure NH to use CurrentSessionContext and
> resolve the session using a factory method
> .AddFacilty<FactorySupportFacility>()
> .Register(Component
> .For<ISession>())
> .UsingFactoryMethod(k=>k.Resolve<ISessionFactory>
> ().GetCurrentSession())
> .LifeStyle.Is(LifeStyleType.Transient));
>
> here is a link for configuring Current Session Context.
http://nhforge.org/wikis/howtonh/currentsessioncontext-for-desktop-de...
> > > > >> > >
rhino-tools-d...@googlegroups.com<rhino-tools-dev%2Bunsubscribe@
googlegroups.com>
> > > <
rhino-tools-dev%2Bunsu...@googlegroups.com<rhino-tools-dev%252Bunsubsc
ri...@googlegroups.com>
>
> > > > >> <
rhino-tools-dev%2Bunsu...@googlegroups.com<rhino-tools-dev%252Bunsubsc
ri...@googlegroups.com>
> > > <
rhino-tools-dev%252Buns...@googlegroups.com<rhino-tools-dev%25252Buns
ubsc...@googlegroups.com>
>
> > > > >> > > .
> > > > >> > > For more options, visit this group at
> > > > >> > >
http://groups.google.com/group/rhino-tools-dev?hl=en.
>
> > > > >> --
>
> > > > >> You received this message because you are subscribed to the Google
> > > Groups
> > > > >> "Rhino Tools Dev" group.
> > > > >> To post to this group, send email to
rhino-t...@googlegroups.com
> > > .
> > > > >> To unsubscribe from this group, send email to
> > > > >>
rhino-tools-d...@googlegroups.com<rhino-tools-dev%2Bunsubscribe@
googlegroups.com>
> > > <
rhino-tools-dev%2Bunsu...@googlegroups.com<rhino-tools-dev%252Bunsubsc
ri...@googlegroups.com>
> > >
rhino-tools-d...@googlegroups.com<rhino-tools-dev%2Bunsubscribe@
googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >
http://groups.google.com/group/rhino-tools-dev?hl=en.- Hide quoted text -
>
> - Show quoted text -