I'm using ninject with wcf to inject parameters into service classes. I now need to do this for a duplex service, and I'm unsure how to proceed.
At the moment, my client invokes the duplex service using a DuplexChannelFactory
like this:
InstanceContext instanceContext = new InstanceContext(new TheCallback());
var factory = new DuplexChannelFactory<IScannerManager>(instanceContext, "ScannerManagerEndPoint");
var channel = factory.CreateChannel();
IClientCallBack is part of my contract for duplex comms:
[ServiceContract(CallbackContract = typeof(IClientCallBack))]
public interface IScannerManager
{
[OperationContract]
void Register(string token);
}
public interface IClientCallBack
{
[OperationContract(IsOneWay = true)]
void SendClientMessage(ScannerMessageWrapper message);
}
I've modified my service ctor to add the new param I want to inject like this:
public ScannerManagerService(Func<IClientCallBack> callBack, IRepositoryFactory repositoryFactory)
{ .. }
Where IRepositoryFactory is what I now want to inject. I've wired up my IRepositoryFactory in my ninject bindings, but when I test the code I see:
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
So ninject is saying it can't see a binding for the callback.. I can't just define a binding for the callback I presume - is this possible with ninject?
Note: This question is similar to Dependency Inject with Ninject 2.0, but I'm asking it again because there are no accepted answers there. In that post the suggestion is made to inject a factory, but I'm unsure how that would look and if it would mean you don't need to use DuplexChannelFactory.
Thanks.