Injecting tenant repositories with StructureMap in a multi-tenant MVC applicaiton
Posted
by FreshCode
on Stack Overflow
See other posts from Stack Overflow
or by FreshCode
Published on 2010-05-01T12:43:58Z
Indexed on
2010/05/01
12:57 UTC
Read the original article
Hit count: 548
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?
© Stack Overflow or respective owner