【发布时间】:2011-06-27 15:29:48
【问题描述】:
我正在使用 ninject 和 wcf 将参数注入服务类。我现在需要为双工服务执行此操作,但我不确定如何继续。
目前,我的客户使用DuplexChannelFactory 调用双工服务,如下所示:
InstanceContext instanceContext = new InstanceContext(new TheCallback());
var factory = new DuplexChannelFactory<IScannerManager>(instanceContext, "ScannerManagerEndPoint");
var channel = factory.CreateChannel();
IClientCallBack 是我的双工通信合同的一部分:
[ServiceContract(CallbackContract = typeof(IClientCallBack))]
public interface IScannerManager
{
[OperationContract]
void Register(string token);
}
public interface IClientCallBack
{
[OperationContract(IsOneWay = true)]
void SendClientMessage(ScannerMessageWrapper message);
}
我已经修改了我的服务 ctor 以添加我想要注入的新参数,如下所示:
public ScannerManagerService(Func<IClientCallBack> callBack, IRepositoryFactory repositoryFactory)
{ .. }
IRepositoryFactory 是我现在要注入的地方。我已经在我的 ninject 绑定中连接了我的 IRepositoryFactory,但是当我测试我看到的代码时:
System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail] : Error activating IntPtr
No matching bindings are available, and the type is not self-bindable.
Activation path:
3) Injection of dependency IntPtr into parameter method of constructor of type Func{IClientCallBack}
2) Injection of dependency Func{IClientCallBack} into parameter callBack of constructor of type ScannerManagerService
1) Request for ScannerManagerService
所以 ninject 说它看不到回调的绑定。我不能只为我认为的回调定义绑定 - ninject 有可能吗?
注意:这个问题类似于Dependency Inject with Ninject 2.0,但我又问了一遍,因为那里没有可接受的答案。在那篇文章中,建议注入一个工厂,但我不确定这会是什么样子,以及这是否意味着你不需要使用 DuplexChannelFactory。
谢谢。
【问题讨论】: