【发布时间】:2019-09-07 06:49:08
【问题描述】:
在我的 .net 框架项目中,我喜欢在我的 app.config 中包含以下内容
<connectionStrings configSource="connections.config" />
connections.config 包含类似
的内容 <connectionStrings>
<add name="ApplicationDatabase" providerName="System.Data.SqlClient" connectionString="Server=.\SQLEXPRESS;Database=mydatabase;User Id=myuser; PWD=mypassword;" />
</connectionStrings>
那我就不把connections.config检入源代码了。
我想对 .NET Core 使用类似的技巧,但它使用了 appsettings.json
通过
services.AddDbContext<ApiDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("MyDatabase")));
我该怎么做?
【问题讨论】:
-
将其移至另一个 json 文件,并在需要时将其与其他设置文件一起加载。文档在这里docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/…
-
这就是答案,想写出来吗?
标签: json asp.net-core