The problem is that your binding here resolves at compile time; whereas you need it to resolve at runtime, for every request. To do this, use ToMethod
:
Bind<ICustomerRepository>().ToMethod(context =>
TenantLookup.LookupByDomain(HttpContext.Current.Request.Url.Host.ToLower()).Foldername == "insideeu"
? new AXCustomerRepository() : new CustomerRepository());
This means that, every time the ICustomerRepository
is called for, NInject will run the method using the current HttpContext
, and instantiate the appropriate implementation.
Note that you can also use Get
to resolve to the type rather than to the specific constructor:
Bind<ICustomerRepository>().ToMethod(context =>
TenantLookup.LookupByDomain(HttpContext.Current.Request.Url.Host.ToLower())
.Foldername == "insideeu" ?
context.Kernel.Get<AXCustomerRepository>() : context.Kernel.Get<CustomerRepository>()
as ICustomerRepository);