Reputation: 10509
In an ASP.NET MVC3 application, I initialize a Ninject IoC container through a
[assembly : WebActivator.PreApplicationStartMethod( typeof (NinjectMVC3), "Start" )]
A class NinjectMVC3
is responsible for my IoC container Kernel
initialization.
After this is called, all controllers, that declare resolvable dependencies through a constructor variables get them resolved just fine.
But I need to use a resolved dependency in Global.asax
Application_Start
method, to feed it to some Custom Global Filters of mine? How can I resolve dependencies in Application_Start
in my scenario?
Upvotes: 0
Views: 2267
Reputation: 32725
In this case you should choose a different way. Inject the dependencies directly to your filters instead of assigning them to the global asax first. This way you solve two problems at once:
The documentation of the Ninject.MVC3 extensions shows how you can create the filters using Ninject so that you can do constructor injection for them:
https://github.com/ninject/ninject.web.mvc/wiki/Dependency-injection-for-filters
Upvotes: 2