Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would do that like this: </p> <ol> <li><p>Introduce an interface that will manage the connection strings:</p> <pre><code>public interface IConnectionStringManager { string GetConnectionString(); } </code></pre></li> <li><p>With the implementation that has IConfigurationProfileProvider injected into it:</p> <pre><code>public class ConnectionStringManager : IConnectionStringManager { private readonly IConfigurationProfileProvider&lt;CustomerProfile&gt; _configurationProfileProvider; public ConnectionStringManager(IConfigurationProfileProvider&lt;CustomerProfile&gt; configurationProfileProvider) { _configurationProfileProvider = configurationProfileProvider; } public string GetConnectionString() { return _configurationProfileProvider.GetProfile().CustomerDatabaseConnectionString; } } </code></pre></li> <li><p>Then inject IConnectionStringManager into CustomerDataContext and get the connection string.</p> <pre><code>public CustomerDataContext(IConnectionStringManager connectionStringManager) { var connectionString = connectionStringManager.GetConnectionString(); // pass the connectionString to your context } </code></pre></li> <li><p>And register ConnectionStringManager and CustomerDataContext as usual:</p> <pre><code>builder.RegisterType&lt;ConnectionStringManager&gt;().As&lt;IConnectionStringManager&gt;(); builder.RegisterType&lt;CustomerDataContext&gt;() .As&lt;ICustomerDataContext&gt;() .As&lt;IDbContext&gt;() .InstancePerDependency(); </code></pre></li> </ol> <p>BTW, Take a look at the <a href="http://code.google.com/p/autofac/wiki/MultitenantIntegration" rel="nofollow">Autofac Multitenant Integration</a> which could ease multitenant support.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload