I'm building a multi tenant (db per tenant) application.
- the application - .net MVC4
- the data layer entity framework code first repositories
- the repositories are injected into the application via structure map
The structuremap config:
var connectionString = ConfigurationManager.ConnectionStrings["AccessControlDB"].ToString();ObjectFactory.Initialize(x => { x.For<IAccessControlContext>().Use<AccessControlContext>().Ctor<string>("connectionString").Is(connectionString); x.For<IGenericRepository<Identities>>().Use<GenericRepository<IAccessControlContext, Identities>>(); x.Scan(scan => { scan.AssembliesFromApplicationBaseDirectory(); scan.ExcludeNamespace("StructureMap"); scan.WithDefaultConventions(); }); });
A new requirement for having each tenant isolated by database has come up, so having tenantIDs is no longer sufficient.
I've gotten as far as having a meta database to store the data required to construct the connection strings, but I'm at a loss on how to pass the connection string to the repository.
At first, I thought I could just expose the connection string as a property, but there is no way to change the connection string after the context has already been instantiated by structuremap.