Ninject to WCF REST Service

I use the WCF REST template, where services are implemented only with the class and are registered in Global.ascx (as well as MVC controllers).

RouteTable.Routes.Add(new ServiceRoute("Games/Games", new WebServiceHostFactory(), typeof(Games.Games)));

Games.Games has a ctor that accepts Dal.Games.IGames, and I have a NinjectModule with ready-made Bindings, but I cannot let my life determine where to transfer the kernel, so that it controls the creation of the service classes.

My services do not have a markup file (svc), so I assume that it will do something with replacing WebServiceHostFactory with one of Ninject. I could find it in the Ninject Web extension, but simply refused it without changing anything, not to mention that I can not find anywhere to configure the channel in this class.

Any solutions, hints or tips are welcome.

+3
source share
1

, , -, Ninject, , . , .

, Ninject.Extensions.Wcf, Ninject .

NinjectServiceHostFactory.cs , .Get <T>

public class NinjectServiceHostFactory : WebServiceHostFactory //<-- Changed base class
{
    protected override ServiceHost CreateServiceHost( Type serviceType, Uri[] baseAddresses )
    {
        var serviceTypeParameter = new ConstructorArgument( "serviceType", serviceType );
        var baseAddressesParameter = new ConstructorArgument( "baseAddresses", baseAddresses );
        return KernelContainer.Kernel.Get<NinjectServiceHost>( serviceTypeParameter, baseAddressesParameter );
    }
}

NinjectServiceHost.cs WebServiceHost.

, :

using System.ServiceModel.Web;

, WCF, , , Ninject .

+4

Source: https://habr.com/ru/post/1784867/


All Articles