0
我有一個ISession作爲Ctor依賴項的域服務。使用SimpleInjector注入ISession時的生活方式不匹配
public JobCreator(IMapper mapper, ISession session)
{
_mapper = mapper;
_session = session;
}
服務註冊爲單身
container.Register<IKindergardenCreator, KindergardenCreator>(Lifestyle.Singleton);
的作爲的Isession但是範圍的登記,因爲會議應該重新不止一次。
container.Register<ISession>(() => container.GetInstance<ISessionFactory>().OpenSession(),
Lifestyle.Scoped);
當我運行該應用程序時,由於此配置,我得到一個「生活方式不匹配」。使用非單例服務配置單例服務的正確方法是什麼?
感謝。我認爲我會將會話工廠注入單例,並讓服務自己創建會話 –