Can't get Ninject Interception to work with WCF
we're switching from UNITY to Ninject as our default service locator for
WCF services. There's a beautiful NuGet package available for doing this
and getting the standard resolution up-and-running is a breeze.
However - I want to intercept the calls to my WCF service. Here's what
I've got:
My svc file:
<%@ ServiceHost Language="C#" Debug="true"
Service="NinjectWcfApp.Service1"
Factory="Ninject.Extensions.Wcf.NinjectServiceHostFactory" %>
Here's my service:
public class Service1 : IService1
{
[Inject]
public ISomeManager Manager { get; set; }
public string GetData(int value)
{
if(this.Manager != null)
this.Manager.DoStuff();
return string.Format("You entered: {0}", value);
}
}
Kernel is built up like this:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<ISomeManager>().To<SomeManager>();
kernel.Bind<IService1>().To<Service1>().Intercept().With<MyInterceptor>();
}
If I setup the kernel like this, the manager instance is injected, but
there's no interception taking place. My interceptor that logs something
before execution and after execution is never invoked.
Other Stackoverflow threads suggest using:
kernel.Bind<Service1>().ToSelf().Intercept().With<MyInterceptor>();
If I do that, the manager is not being injected. If I then go ahead and
create a constructor which takes in the manager, it works, but again: no
interception.
kernel.Bind<Service1>().ToSelf().WithConstructorArgument("manager",
kernel.Get<ISomeManager>()).Intercept().With<MyInterceptor>();
What am I doing wrong here?
No comments:
Post a Comment