0

私は現在、ユニティコンテナとWCFサービスを備えたPRISMアプリケーションを開発中です。モジュールで (WCFプロキシと)次のように私は、WCFクライアントのためのChannelFactoryを登録します。異なるモジュールで解決すると、Unityがタイプを解決できません

InstanceContext instanceContext = new InstanceContext(new TradingPlatformCallback()); 
unityContainer.RegisterType<DuplexChannelFactory<IGenericTradingInterface>, DuplexChannelFactory<IGenericTradingInterface>>(
    new ContainerControlledLifetimeManager(), 
    new InjectionConstructor(
     instanceContext, 
     "NetNamedPipeBinding_IGenericTradingInterface")); 

DuplexChannelFactory<IGenericTradingInterface> factory = unityContainer.Resolve<DuplexChannelFactory<IGenericTradingInterface>>(); 

factory.Open(); 
IGenericTradingInterface test = factory.CreateChannel(); 
test.GetServerInformation(); 
factory.Close(); 

を今、すべてが正常に動作しているので、私は別のモジュールでこののChannelFactoryを使用することにしました。

var test = unityContainer.Resolve<DuplexChannelFactory<IGenericTradingInterface>>(); 
test.Open(); 

var test2 = test.CreateChannel(); 
test2.GetServerInformation(); 
test.Close(); 

だから、このコードは、行方不明の登録を除き、他のモジュールと全く同じ です: はここで、モジュールの初期化メソッドです。

これを実行すると、私は次の例外を取得:

Exception is: InvalidOperationException - The type DuplexChannelFactory`1 has mu 
ltiple constructors of length 3. Unable to disambiguate. 

を解決するとのChannelFactoryのCtorsに問題があるようですが、なぜUnityは最初のモジュールに工場を解決することはできませんこれで?

私が登録して、特定のCTOR呼ばれたと考えられので、私はまた、この例外メッセージを理解していない:任意のアイデア

new InjectionConstructor(
       instanceContext, 
       "NetNamedPipeBinding_IGenericTradingInterface") 

答えて

0

問題はモジュールの初期化の順番であることが判明しました。 2番目のモジュールが最初に呼び出されたので、UnityはCTorを最も多くのパラメータで受け取り、DuplexChannelFactoryは最大で3つあり、多くはそのうちの多くを持っています。おかげで、Juergen

1

ユニティコンテナがモジュール間でどのように共有されているかはわかりません。あなたの変数名( "unityContainer")に基づいて、私はそれがモジュール内のローカル変数だと思いますか?つまり、2つの別々のコンテナインスタンスがあり、それぞれに登録が必要です。

関連する問題