Error activating IProductRepository, ninject issue learning With Apress Pro ASP.NET MVC 5 -
hello i'm reading book "apress pro asp.net mvc 5" have downloaded chapter 7, running application using ninject. first issue
1st issue snagit read ninject issue versiĆ³n solved adding code sportsstorewebui web.config:
enter code here <runtime> <assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentassembly> <assemblyidentity name="system.web.mvc" publickeytoken="31bf3856ad364e35" /> <bindingredirect oldversion="1.0.0.0-5.0.0.0" newversion="5.0.0.0" /> </dependentassembly> </assemblybinding> </runtime>
now when try run app issue.
error activating iproductrepository no matching bindings available, , type not self-bindable.
activation path:
1) injection of dependency iproductrepository
parameter productrepository of constructor of type productcontroller
2) request productcontroller
suggestions:
1) ensure have defined binding iproductrepository
.
2) if binding defined in module, ensure module has been loaded kernel.
3) ensure have not accidentally created more 1 kernel.
4) if using constructor arguments, ensure parameter name matches constructors parameter name.
5) if using automatic module loading, ensure search path , filters correct.
the content of ninjectwebcommon.cs is
[assembly: webactivatorex.preapplicationstartmethod(typeof(sportsstore.webui.app_start.ninjectwebcommon), "start")] [assembly: webactivatorex.applicationshutdownmethodattribute(typeof(sportsstore.webui.app_start.ninjectwebcommon), "stop")] namespace sportsstore.webui.app_start { using system; using system.web; using microsoft.web.infrastructure.dynamicmodulehelper; using ninject; using ninject.web.common; public static class ninjectwebcommon { private static readonly bootstrapper bootstrapper = new bootstrapper(); /// <summary> /// starts application /// </summary> public static void start() { dynamicmoduleutility.registermodule(typeof(oneperrequesthttpmodule)); dynamicmoduleutility.registermodule(typeof(ninjecthttpmodule)); bootstrapper.initialize(createkernel); } /// <summary> /// stops application. /// </summary> public static void stop() { bootstrapper.shutdown(); } /// <summary> /// creates kernel manage application. /// </summary> /// <returns>the created kernel.</returns> private static ikernel createkernel() { var kernel = new standardkernel(); try { kernel.bind<func<ikernel>>().tomethod(ctx => () => new bootstrapper().kernel); kernel.bind<ihttpmodule>().to<httpapplicationinitializationhttpmodule>(); registerservices(kernel); return kernel; } catch { kernel.dispose(); throw; } } /// <summary> /// load modules or register services here! /// </summary> /// <param name="kernel">the kernel.</param> private static void registerservices(ikernel kernel) { } } }
i have looked don't found error.
thank much.
you didn't add registerservices in ninjectwebcommon:
system.web.mvc.dependencyresolver.setresolver(new ninjectdependencyresolver(kernel));
Comments
Post a Comment