1

Castle を使用して NCommon IRepository として NHibernate エンティティを自動登録しようとしていますが、わかりません。

以前のプロジェクトでは autofac を使用しました。

autofacContainerBuilder.RegisterGeneric(typeof (NHRepository<>))
                .As(typeof (IRepository<>))
                .InstancePerLifetimeScope();

Castleに相当するものはありますか?ありがとう!

編集:

これは可能な限り近いものですが、ComponentActivator は NHRepository のインスタンス化に失敗します。

.Register(Component.For(typeof(IRepository<>))
                   .ImplementedBy(typeof(NHRepository<>))
                   .LifeStyle.Transient)

ComponentActivator は NCommon.Data.NHibernate.NHRepository をインスタンス化できませんでした

手動でインスタンス化すると失敗します:

NHRepository<MyEntity> blah = new NHRepository<MyEntity>();

と:

*オブジェクト参照が c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocator.cs:line 17 の Microsoft.Practices.ServiceLocation.ServiceLocator.get_Current() でオブジェクトのインスタンスに設定されていません*

解決済み:

私はこれを見逃していました:

ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(Container));

WindsorServiceLocator は次の場所で入手できます。

http://commonservicelocator.codeplex.com/wikipage?title=Castle%20Windsor%20Adapter&referringTitle=ホーム

詳細はこちら:

http://prashantbrall.wordpress.com/2010/11/22/service-locator-pattern-with-windsor-castle/

4

1 に答える 1

1

私はこれを見逃していました:

ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(Container));

WindsorServiceLocator は次の場所で入手できます。

http://commonservicelocator.codeplex.com/wikipage?title=Castle%20Windsor%20Adapter&referringTitle=ホーム

詳細はこちら:

http://prashantbrall.wordpress.com/2010/11/22/service-locator-pattern-with-windsor-castle/

于 2012-03-16T23:48:19.397 に答える