Question

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

Now I need to set some dependencies per query in this way:

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

I thougt some of Request-specific methods of Global_asax would be a nice place for and tried to access some of NinjectHttpApplicaton properties to register dependencies per request. I accessed Kernel and got obsolete warning "Don't use Ninject as Service locator". What am I doing wrong? How to do it right?

Was it helpful?

Solution

To change the implementation based on some condition like language you should use conditional bindings. E.g. Bind<IFoo>().To<Foo>().When(ctx => Language == Language.English)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top