我目前正在使用统一容器和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")
任何想法?