Skip to content

Dependency injection for WCF behaviors

Scott Xu edited this page Apr 8, 2014 · 6 revisions

From version 3.2, this extension support dependency injection for WCF behaviors:

config file:

<system.serviceModel>
...
  <extensions>
    <behaviorExtensions>
      <add name="yourBehaviorName" type="Ninject.Extensions.Wcf.BaseNinjectBehaviorExtensionElement+NinjectBehaviorExtensionElement`1[[YourAssembly.YourBehavior, YourAssembly]], Ninject.Extensions.Wcf" />
    </behaviorExtensions>
  </extensions>
...
</system.serviceModel>

When application start, set the kernel:

BaseNinjectBehaviorExtensionElement.SetKernel(yourKernel);

Or just use the bootstrapper.