开发者

Is it possible to use Ninject with a static property?

开发者 https://www.devze.com 2022-12-14 12:50 出处:网络
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 th

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消