Created
February 4, 2020 15:25
-
-
Save misha130/910508d3019d3d3bfa64dfb609df70f4 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
services.AddDbContext<ApplicationDbContext>((scope, options) => | |
{ | |
var context = scope.GetRequiredService<IActionContextAccessor>(); | |
string connectionString = "DefaultConnection"; | |
var actionContext = context.ActionContext; | |
if (actionContext != null) | |
{ | |
var routeValues = actionContext.RouteData.Values; | |
if (routeValues.ContainsKey("community")) | |
{ | |
connectionString = routeValues["community"].ToString(); | |
} | |
} | |
options.UseNpgsql( | |
configuration.GetConnectionString(connectionString), | |
b => b.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks good, but here's a slight nitpick...
Won't this part just get the community name / community id from the routing data?
It's not really a connection string, the variable name is a bit misleading.