如何提供可以通过asp.net 5中的ConfigurationManager进行访问的设置? [英] How can I provide settings that can be accessed through ConfigurationManager in asp.net 5?

查看:115
本文介绍了如何提供可以通过asp.net 5中的ConfigurationManager进行访问的设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何提供可以通过asp.net 5中的 ConfigurationManager 访问的设置?

How can I provide settings that can be accessed through ConfigurationManager in asp.net 5?

我使用的旧软件包不支持新的 Microsoft.Framework.ConfigurationModel ,并且正在寻找ConfigurationManager来获取连接字符串,应用程序设置甚至配置部分.将app.config添加到项目似乎没有任何效果.

I am using older packages that do not support the new Microsoft.Framework.ConfigurationModel and are looking to the ConfigurationManager to get connection strings, app settings, and even configuration sections. Adding an app.config to the project does not appear to have any effect.

例如,app.config:

For example, app.config:

<configuration>
  <connectionStrings>
    <add name="logging" connectionString="Server=.\SQLExpress;Database=logging;Trusted_Connection=True;"/>
  </connectionStrings>
</configuration>

ConfigurationManager.ConnectionStrings ["logging"] 返回null.相反, ConfigurationManager.ConnectionStrings 仅包含machine.config的默认值.

ConfigurationManager.ConnectionStrings["logging"] returns null. Instead, the ConfigurationManager.ConnectionStrings only contains the machine.config defaults.

推荐答案

似乎他们决定完全弃用System.Configuration.因此,假设(我猜)是,如果您有一个从web/exe.config(通过 ConfigurationManager )读取某些配置的库,那么您将不得不想出自己的语法来进行配置,从 Startup 中的json/xml/whatever中读取它,并自行通过其api初始化lib.这有点像控制权的倒置.

It seems that they decided to deprecating System.Configuration at all. So it's supposed (I'm guessing) that if you a lib which reads some configuration from web/exe.config (via ConfigurationManager) then you'll have to come up with out own syntax for configuring, read it from json/xml/whatever in Startup and initialize the lib via its api on your own. It's kinda inversion of control.

我在此问题中要求团队提供更清晰的文档.

I asked the team for more clear docs in this issue.

这篇关于如何提供可以通过asp.net 5中的ConfigurationManager进行访问的设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆