9
votes

I am currently using Ninject (2.2.1.4) and Ninject.Extensions.Wcf (2.2.0.4) with my WCF service. I would like to upgrade to Ninject (3.0.0.15) and Ninject.Extensions.Wcf (3.0.0.5) and it doesn't look like I can use my current approach anymore. Can anyone point me to some samples or posts on how to get the latest version of Ninject working with a WCF project.

My current approach:

I wrote a module:

public class NinjectDependencyResolver : NinjectModule
{
    public override void Load()
    {
        // Declare bindings
    }
}

I added the Factory Attribute to my .svc file

Factory="Ninject.Extensions.Wcf.NinjectServiceHostFactory"

I added a Global.asax to the WCF project

public class Global : NinjectWcfApplication
{
    protected override IKernel CreateKernel()
    {
        return new StandardKernel(new NinjectDependencyResolver());
    }
}

Now I can modify the default constructor in my service and use constructor injection.

Any pointers on how I could upgrade are appreciated.

Thanks

1

1 Answers

12
votes

Add Ninject.Web.Common and derive from NinjectHttpApplication or use the App_Start file that comes with the NuGet package.