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 facing is that I would like to remove the add attribute from the base controller and instead specify this in the Ninject ServiceModule. I would like to say how can I write a binding rule in a ServiceModule that tells Ninject to inject a ProductService into a property in the base controller?
If I remove the attribute, I will get a NullReferenceException.
source
share