Skip to content

Dependency injection for WCF behaviors

foggerty edited this page Jul 2, 2015 · 6 revisions

Starting from version 3.2, this extension supports dependency injection for WCF behaviors:

config file:

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

Next, you'll need to add this extension to a behavior:

...
<behavior name="BehaviorName">
  <yourBehaviorName />
  <serviceMetadata httpGetEnabled="true" />
  <serviceDebug includeExceptionDetailInFaults="true" />                     
</behavior>
...

Ensure that your extension is the first element in that list.

Note: You're likely to get the following warning:

The element 'behavior' has invalid child element 'yourBehaviorName' List of possible elements expected......

From what Google tells me this cannot be removed, but if you mange it then please update this page!