使用Microsoft.Extensions.Configuration

时间:2019-07-19 07:56:17

标签: c# .net-core application-settings

我试图弄清楚如何访问类库中的应用程序设置。在控制台应用程序中读取并构建应用程序设置,并且项目引用的类库必须访问这些设置,因为该库是数据访问层,并且需要访问连接字符串。

在主控制台应用中,我有此代码-正常工作

   var config = new ConfigurationBuilder()
                    .AddJsonFile("appsettings.json", optional: true, loadOnChange: true)
    .Build();

                Console.WriteLine($"Contents of Message Property: {config["Message"]}");

如何访问项目引用的类库中的信息。我想没有必要用每个库中的设置重新读取json文件吗?

0 个答案:

没有答案
相关问题