views:

149

answers:

1

I have a static SessionFactory class that initializes an NHibernate session factory. Because this process is expensive (~5 sec.), I want it to be static so it's only done once, at the beginning of runtime.

The configuration can take a database parameter parameter like so:

public static IPersistenceConfigurer DbConfig { get; set; }

public static void Initialize()
{
    var cfg = Fluently.Configure()
                      .Database(DbConfig)
                      .Mappings(some mappings)
                      .BuildConfiguration();
}

Is it possible to use Ninject to inject DbConfig with the correct constant?

+1  A: 

Instead of making this static, register the ISessionFactory instance (ToConstant()) then register the ISession with a request scope (InRequestScope)

This thread explains it quite clearly.

Mauricio Scheffer