Created
June 11, 2018 22:21
-
-
Save explorer14/c0a850e8c6f39f2b522437f25c1b7ec0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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