I'm using ASP.NET MVC 5, with Ninject 3.
I want to have some code run when the web site starts, which will pull something from the database. I already have injection set up, and it's working fine elsewhere in the project.
I changed the Global.asax
file to look like this...
[Inject]
public VoucherCompanyServiceLogicInterface VoucherCompanyServiceLogic { get; set; }
protected void Application_Start() {
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
VoucherCompany vc = VoucherCompanyServiceLogic.GetByID(1, 1);
}
...but the VoucherCompanyServiceLogic
property is always null. I copied the two lines for this (the Inject
attribute and the property declaration) from another class where they work fine.
I put some Debug.WriteLine
statements in this method, and in the RegisterServices
method of the NinjectWebCommon
class, and I can see that the services are being registered before I try to use this one, so that's not the issue.
Anyone any idea why this is always null?