Injecting tenant repositories with StructureMap in a multi-tenant MVC applicaiton
- by FreshCode
I'm implementing StructureMap in a multi-tenant ASP.NET MVC application to inject instances of my tenant repositories that retrieve data based on an ITenantContext interface. The Tenant in question is determined from RouteData in a base controller's OnActionExecuting.
How do I tell StructureMap to construct TenantContext(tenantID); where tenantID is derived from my RouteData or some base controller property?
Base Controller
Given the following route:
{tenant}/{controller}/{action}/{id}
My base controller retrieves and stores the correct Tenant based on the {tenant} URL parameter. Using Tenant, a repository with an ITenantContext can be constructed to retrieve only data that is relevant to that tenant.
Based on the other DI questions, could AbstractFactory be a solution?