开发者

Ninject register per request

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 Req开发者_StackOverflow中文版uest-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?


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜