Ninject MVC along with WCF extension does not work with InRequestScope

I got Ninject MVC to work with Ninject WCF to get it working. I added two lines to the CreateKernel method

kernel.Bind<ServiceHost>().To<NinjectServiceHost>();
KernelContainer.Kernel = kernel;

Dependencies are introduced, but the Dispose method is not called, I tried both with InRequestScope and ran my own scope. Func returned OperationContext.Current as a Scope, but dispose is not called.

Update 2012-09-05 This information is outdated, for loading MVC and WCF from Nuget Ninject.MV3 and Ninject.Extensions.WCF (3.x) MVC Nuget template will add Ninject bootstrapper NinjectWebCommon.cs and add support in svc for ninject eddit svc xml (right click / Open Markup) and add Factory = "Ninject.Extensions.Wcf.NinjectServiceHostFactory" in the xml node

+5
source share
2 answers

I cannot answer Remo's answer because I am stackoverflow n00b, but the problem with System.Runtime.CompilerServices.ExtensionAttribute exception is that it has moved from System.Core in .net 4.0 to mscorlib. net 4.5. If you install .net 4.5, the problem goes away. I think something was built with .net 4.5 in the mix. https://github.com/ninject/Ninject.Web.Common/issues/3 It looks like it will be fixed soon. Regarding the Wcf InRequestScope problem, Remo gave me some help today in google groups ... "add a new module that comes from" Ninject.GlobalKernelRegistrationModule "and load it into the kernel. This will be fixed for the final version."

i.e. sort of...

public class MyModule : Ninject.GlobalKernelRegistrationModule<WcfRequestScopeCleanup>
{
}

//And where you load your modules...
kernel.Load<MyModule>();
+2

Ninject 3.0.0-rc2, Nuget. InRequestScope Web, WCF- .

+2

All Articles