Upgrading Ninject/Ninject WCF Extensions to the latest version 3.0.0.5

孤街醉人 提交于 2019-12-18 04:46:11

问题


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:


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



来源:https://stackoverflow.com/questions/10390809/upgrading-ninject-ninject-wcf-extensions-to-the-latest-version-3-0-0-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!