Last active
June 24, 2021 18:46
-
-
Save gavilanch/f52699432e425a02b1128e1e09bf0d96 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); | |
services.AddDbContext<ApplicationDbContext>((serviceProvider, dbContextBuilder) => | |
{ | |
var connectionStringPlaceHolder = Configuration.GetConnectionString("PlaceHolderConnection"); | |
var httpContextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>(); | |
var dbName = httpContextAccessor.HttpContext.Request.Headers["tenantId"].First(); | |
var connectionString = connectionStringPlaceHolder.Replace("{dbName}", dbName); | |
dbContextBuilder.UseSqlServer(connectionString); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment