在ConfigureServices

时间:2018-05-12 19:50:32

标签: asp.net-core configuration environment-variables connection-string

我有3个连接字符串。默认为EF Core迁移管理,Container用于使用docker进行开发。

appsettings.json

{
  "ConnectionStrings": {
    "Default": "Server=localhost,1433;Database=Identity;User Id=sa;Password=yourStrong(!)Password",
    "Container": "Server=identity_db,1433;Database=Identity;User Id=sa;Password=yourStrong(!)Password",
    "Production": "Server=localhost,1433;Database=Identity;User Id=sa;Password=yourStrong(!)Password"
  }
}

我在ConfigureServices中添加DbContext

services.AddDbContext<ApplicationDbContext>(options =>
{
   options.UseSqlServer(Configuration.GetConnectionString("Default"));
});

如何根据环境获取connectiong字符串? IE浏览器。得到&#34;默认&#34;如果是IHostingEnvironment.IsDevelopment == true

0 个答案:

没有答案