I want to create instance of PerRequestResourceProvider using ninject InRequestScope:
public class PerRequestResourceProvider: IPerRequestResourceProvider
{
There are two issues with your code:
Ninject is not getting initialized correctly. You need one of the Ninject.MVCx packages (according to the MVC version you are using). To configure it correctly, see: http://github.com/ninject/ninject.web.mvc
You are injecting PerRequestResourceProvider
(the class type), and not IPerRequestResourceProvider
(the interface type) into HomeController
, thus the .InRequestScope()
defined on the IPerRequestResourceProvider
binding is not taking any effect. Change the HomeController
constructor to get the inteface type injected and you're good.
Ninject does not require bindings for instantiatable (non-abstract,..) classes. This is why it is not obvious when the wrong binding is used.