In support of multi-tenancy, setting up routing:
{controller}/{tenantId}/{action}/{id?}
When the controller is instantiated, via the IoC framework in MVC6, the constructor takes a model (IUserStore<ApplicationUser>
) that manages access to users and needs the tenantId in its constructor. The DI container is barfing right now b/c it doesn't have the tenantId.
I'd like to be able to register the model thusly:
services.TryAddTransient(typeof(IUserStore<CazadorUser>, (IServiceProvider isp) =>
{
return new TenantUserStore<ApplicationUser>(isp.GetService<DbContext>(), "Can I get the tenant ID from the IServiceProvider as its in the route?");
}));
If I cannot access the parsed route, is there another way to get the tenant ID into the DI-hydrated controller (or, rather, the ctor parameter of the DI-hydrated controller that is DI-hydrated)?