我试图将NHibernate实体自动注册为NCommon IRepository正在使用的城堡,但我搞不懂。
在之前的一个项目中,我们使用了autofac,这就是我们如何实现它的方法:
autofacContainerBuilder.RegisterGeneric(typeof (NHRepository<>))
.As(typeof (IRepository<>))
.InstancePerLifetimeScope();卡塞尔有等价物吗?谢谢!
编辑:
这是我所能得到的最接近的,但是ComponentActivator在实例化NHRepository时失败了:
.Register(Component.For(typeof(IRepository<>))
.ImplementedBy(typeof(NHRepository<>))
.LifeStyle.Transient)ComponentActivator无法实例化NCommon.Data.NHibernate.NHRepository
手工实例化爆炸:
NHRepository<MyEntity> blah = new NHRepository<MyEntity>();通过以下方式:
*对象引用未设置为Microsoft.Practices.ServiceLocation.ServiceLocator.get_Current()中的c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocator.cs:line 17中的对象实例*
已解决:
我错过了这个:
ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(Container));WindsorServiceLocator可在这里获得:
http://commonservicelocator.codeplex.com/wikipage?title=Castle%20Windsor%20Adapter&referringTitle=Home
更多信息在这里:
http://prashantbrall.wordpress.com/2010/11/22/service-locator-pattern-with-windsor-castle/
发布于 2012-03-16 23:48:19
我错过了这个:
ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(Container));WindsorServiceLocator可在这里获得:
http://commonservicelocator.codeplex.com/wikipage?title=Castle%20Windsor%20Adapter&referringTitle=Home
更多信息在这里:
http://prashantbrall.wordpress.com/2010/11/22/service-locator-pattern-with-windsor-castle/
https://stackoverflow.com/questions/9739647
复制相似问题