我目前正在使用統一容器和WCF服務的PRISM應用程序。 在模塊(與WCF代理),我註冊的ChannelFactory爲WCF客戶端如下:統一無法解析類型,當在一個不同的模塊解析
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的構建函數,但團結爲什麼可以解決工廠第一模塊中,而不是一個問題在這一個?
我也弄不明白這個異常消息,因爲我認爲在與註冊已經稱爲一個特定的構造函數:
new InjectionConstructor(
instanceContext,
"NetNamedPipeBinding_IGenericTradingInterface")
任何想法?