I setup a CustomRoleProver as:
public class CustomRoleProvider : RoleProvider
{
private readonly IRepository _repository;
pu
In order to setup Ninject personally I would create a factory class within your project as per below.
Note, the AddBindings method where you configure the DI bindings.
public class NinjectControllerFactory : DefaultControllerFactory
{
private IKernel ninjectKernel;
public NinjectControllerFactory()
{
ninjectKernel = new StandardKernel();
AddBindings();
}
protected override IController GetControllerInstance(RequestContext requestContext,
Type controllerType)
{
return controllerType == null
? null
: (IController)ninjectKernel.Get(controllerType);
}
private void AddBindings()
{
// put bindings here
ninjectKernel.Bind<IRepository<User>>().To<Repository<User>>();
}
}
Register the factory within Application_Start of Global.asax.cs:
ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());
Most likely you are using an invalid custom dependency resolver. Read https://github.com/ninject/ninject.web.mvc/wiki/MVC3 about how to use the Ninject.MVC3 extension instead.
You're writing a roleprovider, but these are not currently DI aware. A lot of the classes in MVC are DI aware, which is why you see it workign with controllers.
To be able to inject a constructor parameter the DI container has to be responsible for creating the object you're hoping to inject into. Just registering a type does not magically make it locatable.
With roleproviders, it is the Roles class within the framework that create instances of the providers, including your custom provider. It only works parameterless constructors. You'll need to use something like property injection within your custom provider and use Roles.Provider to get the instance to inject your dependencies into.