StructureMap: Calling repository constructor based on RouteData
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:47 UTC
Read the original article
Hit count: 247
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?
© Stack Overflow or respective owner