I have the following code in my Global.aspx
protected override void OnApplicationStarted()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
RegisterAllControllersIn(Assembly.GetExecutingAssembly());
}
protected override IKernel CreateKernel()
{
return new StandardKernel(new ServiceModule());
}
I also have the following Ninject Module:
internal class ServiceModule : NinjectModule
{
public override void Load()
{
Bind<IProductService>().To<ProductService>().InRequestScope();
}
}
I also have a base controller:
public class BaseController : Controller
{
[Inject]
public IProductService ProductService
{
get;
set;
}
}
This code works. The problem I am having is that I would like to remove the inject attribute from the base controller and specify this in the Ninject ServiceModule instead. I other words, how would I go about writing a binding rule in the ServiceModule that tells Ninject to inject ProductService into the property in the base controller?
If I remove the attribute I will get a NullReferenceException.