开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜