IA1
2 つのアプリケーション インターフェイスを介してアクセスする 2 つのドメインがありIA2
、それぞれが異なるリポジトリR1
と を使用しますR2
。リポジトリは、NHibernate セッションを作成できるインターフェースを使用しますISimpleSessionFactory
。
リポジトリがデータベースを共有している場合、unity コンテナーを使用して、次のように両方をセットアップします。
var unity = new UnityContainer();
unity.RegisterType<ISimpleSessionFactory, NHibernateSessionFactory>(
new ContainerControlledLifetimeManager(), new InjectionConstructor("ConnectionA"));
unity.RegisterType<IA1, A1>();
unity.RegisterType<R1>();
unity.RegisterType<IA2, A2>();
unity.RegisterType<R2>();
しかし、それらは接続文字列を共有していないので、次のようなことをしたいと思います:
var unity = new UnityContainer();
var child1 = unity.CreateChildContainer();
child1.RegisterType<ISimpleSessionFactory, NHibernateSessionFactory>(
new ContainerControlledLifetimeManager(), new InjectionConstructor("ConnectionA"));
child1.RegisterType<IA1, A1>();
child1.RegisterType<R1>();
var child2 = unity.CreateChildContainer();
child2.RegisterType<ISimpleSessionFactory, NHibernateSessionFactory>(
new ContainerControlledLifetimeManager(), new InjectionConstructor("ConnectionB"));
child2.RegisterType<IA2, A2>();
child2.RegisterType<R2>();
しかし、私の問題は、クラスから解決IA2
したいということです。A1
理想的には、セッション ファクトリ以外のすべてを親コンテナーに格納したいと考えています。それは単なるリポジトリでR1
ありR2
、異なるISimpleSessionFactory
s が必要ですが、私が理解しているように、子でローカルに解決されない場合にのみ親にフォールバックするため、何かを親に移動するとセッションファクトリが見つかりません。