Is it possible to use Ninject with a static property?

I have a static class SessionFactorythat initializes an NHibernate factory session. Since this process is expensive (~ 5 seconds), I want it to be static, so it only runs once at the start of execution.

The configuration can accept a database parameter parameter as follows:

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 a DbConfig with the correct constant?

+3
source share
1 answer

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

.

+3

Source: https://habr.com/ru/post/1725676/


All Articles