Wednesday 15 September 2010

ninject - How can I resolve a dependency on something on the current request? -



ninject - How can I resolve a dependency on something on the current request? -

i'm setting dependency injection in asp.net web api application. have scenario dependency has dependency on on current request (the hostname, example).

so how can utilize current request dependency?

below i've been able come with, httpcontext.current won't work in self-hosted scenario.

kernel.bind<ifoo>() .tomethod((context) => { string hostname = httpcontext.current.request.url.host; var foo = foofactory.getbyhostname(hostname); homecoming foo; }) .inrequestscope();

i'm using ninject, can switch different ioc container if there's 1 can handle scenario better.

ninject ioc-container

No comments:

Post a Comment