Contents tagged with Windsor

  • So I Created Another Utils Library

    Thought it was time I start my own Utils library (why not everyone else seems to have one), I have things like a UnitOfWork implementation, base Repository class, and plan to add more things as I go.

    This is still a work in progress and I would appreciate any feedback out there, in the meantime I will continue my work on it.

    You can find the project on GitHub @ http://github.com/stefansedich/YetAnotherUtilsLib


    Cheers
    Stefan

  • NHibernate Session Management using FluentNhibernate and Castle Windsor

    Time for my first post in a while, thought I would post on session management using Castle Windsor.

    I found this good post, http://blog.stevehorn.cc/2009/03/fluent-nhibernate-configured-via.html and I have basically converted it to use Castle for IoC instead.

    The Windsor config that will work is below:

    var container = new WindsorContainer();
    container.AddFacility(); // This adds support to be able to use the UsingFactoryMethod.

    container.Register(Component.For().ImplementedBy().LifeStyle.Singleton);
    container.Register(Component.For().UsingFactoryMethod(x => x.Resolve() .GetSessionFactory() .OpenSession()).LifeStyle.PerWebRequest);

    The only other addition that is needed for Windsor is to add the PerWebRequest module to your Web.config file in the httpModules section:

    <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel" />

    And you are done, nice and simple NHibernate Session management using a Windsor container.



    Cheers Stefan

  • Avoid Memory Leaks When Using Windsor And Not Releasing Objects

    I just had this issue in a project I am working on (ASP.NET Webforms Application), yesterday I ran a load test and watched my memory climb rapidly and max out not long after. I am using Castle Windsor for my IOC and mostly transient instances are registered so I did not expect any issues here as I asssumed there would be no references held to my transient instances but the leak shows this is happening.

    I am not releasing my services once done so this is partly my fault but I do not wan't to explicitly release them so I found another way which means setting the ReleasePolicy on the kernel to use the NoTrackingReleasePolicy. The default release policy is the AllComponentsReleasePolicy which from what I can see by debugging will keep track of your instances and you will need to release them manually when you are finished with the item.