Skip to content

Instantly share code, notes, and snippets.

@explorer14
Created June 11, 2018 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save explorer14/c0a850e8c6f39f2b522437f25c1b7ec0 to your computer and use it in GitHub Desktop.
Save explorer14/c0a850e8c6f39f2b522437f25c1b7ec0 to your computer and use it in GitHub Desktop.
public class DbContextFactory : IDbContextFactory
{
private string connectionStringTemplate;
public string TenantName { get; set; }
public DbContextFactory(string connectionStringTemplate)
{
this.connectionStringTemplate = connectionStringTemplate;
}
public CRMContext Create()
{
CRMContext context = null;
if (!string.IsNullOrWhiteSpace(this.TenantName))
{
var dbContextOptionsBuilder = new DbContextOptionsBuilder();
dbContextOptionsBuilder.UseSqlServer(this.connectionStringTemplate
.Replace("{tenant}", this.TenantName));
context = new CRMContext(dbContextOptionsBuilder.Options);
}
return context;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment