我目前正在使用autofac进行DI和nhibernate。我目前正在注入我的ISessionFactory和ISessions,但我也希望能够注入我的实体。为此,我发现了以下内容(http://chadly.net/2009/05/dependency-injection-with-nhibernate-and-autofac/)
containerProvider = new ContainerProvider(builder.Build());
Environment.BytecodeProvider = new AutofacBytecodeProvider(
containerProvider.ApplicationContainer, new ProxyFactoryFactory());
必须在调用Configure()之前调用它,并且还需要构建器来构建容器。
这与ISessionFactory注册不一致,该注册必须在 构建容器之前发生。
所以,问题是:如何注册我的ISessionFactory 和为实体注入配置BytecodeProvider?
感谢。