Hod do you inject some class based on request host value? I installed Ninject MVC3 lib via Nuget. I'm looking for something like this:
private static void RegisterServices(IKernel kernel)
{
var host = get host from request;
if (host.StartstWith("x."))
{
kernel.Bind<IMyInterface>().To<XImplementation>().InRequestScope();
}
else if (host.StartstWith("y."))
{
kernel.Bind<IMyInterface>().To<YImplementation>().InRequestScope();
}
}
Edit: just found this answer.. is there any other way than factory? Like the one in my "pseudo" example above?
Solution:
private static void RegisterServices(IKernel kernel)
{
var host = HttpContext.Current.Request.Headers["host"].ToLower();
kernel.Bind<IMyInterface>().To<XImplementation>().When(ctx => host.StartsWith("x.")).InRequestScope();
kernel.Bind<IMyInterface>().To<YImplementation>().When(ctx => host.StartsWith("y.")).InRequestScope();
}