StructureMap: Calling repository constructor based on RouteData
- by FreshCode
I'm implementing a multi-tenant ASP.NET MVC application and using StructureMap for DI where my repositories depend on an ITenantContext interface, which depends on RouteData (or a base controller property).
How do I tell StructureMap to construct TenantContext(tenantID); where tenantID is derived from my RouteData or some base controller property?
Given the following route:
{tenant}/{controller}/{action}
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, AbstractFactory could be a solution?solution?