Is it possible to use Ninject with a static property?
I have a static SessionFactory
class that initializes an NHibernate session fa开发者_如何学编程ctory. 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?
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.
精彩评论