ovesens.NET library

A library with enhancements for NHibernate and Castle Windsor, and it adds support for dependency injection for WebForms.

I use this library with Umbraco and it incudes:

  • NHibernate
  • NHibernate caching
  • NHibernate proxy (LinFu)
  • NHibernate.Linq
  • FluentNHibernate
  • Castle Windsor
  • Log4net
  • ovesens.NET libraries (NHibernateLib, WindsorLib and UtilityLib)
  • Demo: Macro and Usercontrol for demo of IoC usage

What do all this do?

It first adds NHibernate support for your application. the ovesens.NET libraries adds some enhancements to the NHibernate library + it also adds support for IoC (Inversion Of Control/Dependency Injection) in your WebForms usercontrols using the Inject attribute.

This package includes a simple Macro that illustrates how IoC is used with WebForms.

How to use

1. Install package in Umbraco

2. Insert the following in the Global.asax

void Application_Start(object sender, EventArgs e)
    {
        // This make sure that but ~/App_Data/Logs and ~/App_Data/Logs is created
        var logFolders = Server.MapPath(@"~/App_Data/Logs/");

        if (!Directory.Exists(logFolders))
        {
            Directory.CreateDirectory(logFolders);
        }

        // Initialize log4net
        Log.EnsureInitialized();

        // Register base types for NHibernate using Castle Windsor IoC
        IoC.GetContainer()
            .Register(

                Component.For<ISessionBuilder>().ImplementedBy<HybridSessionBuilder>().LifeStyle.Singleton,
                Component.For(typeof (IRepository<,>)).ImplementedBy(typeof (Repository<,>)).LifeStyle.Transient,

                // For testing only
                Component.For().ImplementedBy().LifeStyle.Transient

        );
}

3.Insert the following to your web.config in the httpmodule section of both system.web and system.webserver

<add name="NHibernateSessionModule" type="ovesens.NET.NHibernateLib.NHibernateSessionModule, ovesens.NET.NHibernateLib" />
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel" />
<add name="Windsor" type="ovesens.NET.WindsorLib.WindsorHttpModule, ovesens.NET.WindsorLib" />

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>