Get the HTTP Context base
builder.RegisterHttpRequestMessage(GlobalConfiguration.Configuration);
builder.Register<HttpContextBase>(c =>
{
var context = (HttpContext.Current != null) ?
new HttpContextWrapper(HttpContext.Current) :
c.Resolve<System.Net.Http.HttpRequestMessage>().Properties["MS_HttpContext"] as HttpContextWrapper;
return context;
}).InstancePerRequest();
Resolve the dependency based on the request header value
builder.Register(c =>
{
var route = c.Resolve<HttpContextBase>().Request.Headers.Get("provider");
if (route == null)
{
throw new ArgumentNullException($"A route must be specified");
}
return c.ResolveNamed<IInterfaceName>(route);
}).InstancePerRequest();
No comments:
Post a Comment