Register Ninject per request

My ASP.NET MVC 3 application uses the integration of Ninject and Ninject ASP.NET MVC 3. I overloaded the CreateKernel method.

Now I need to install some dependencies for each request this way:

if (Language == Language.English) //register English language implementations else if (Language == Language.Russian) //register Russain language implementations 

Some special request-specific Global_asax methods would be a nice place and try to access some of the NinjectHttpApplicaton properties to register dependencies per request. I got access to the kernel and got an outdated warning "Do not use Ninject as a service locator." What am I doing wrong? How to do it right?

+4
source share
1 answer

To change an implementation based on some state, such as a language, you must use conditional bindings. For instance. Bind<IFoo>().To<Foo>().When(ctx => Language == Language.English)

+5
source

All Articles