简体   繁体   English

在.NET核心中使用app.config和ConfigurationManager是否可取?

[英]Is using app.config and ConfigurationManager in .NET core advisable?

We are migrating some .NET applications from full framework to .NET core and we are trying to find out the best way to do so. 我们正在将一些.NET应用程序从完整框架迁移到.NET核心,我们正在尝试找到最佳方法。

One of the major changes is the one related to the way applications are configured. 其中一个主要变化是与应用程序配置方式相关的变化。 In the .NET full framework we used to put application settings inside the app.config file and to read them by means of the ConfigurationManager class . 在.NET完整框架中,我们习惯将应用程序设置放在app.config文件中,并通过ConfigurationManager类读取它们。

I know that .NET core supports a new configuration system based on the nuget package Microsoft.Extensions.Configuration and the various packges for the configuration sources. 我知道.NET内核支持基于nuget包Microsoft.Extensions.Configuration的新配置系统以及配置源的各种包。 However, at the same time, Microsoft has extended the support for the ConfigurationManager class to .NET core, by means of the nuget package System.Configuration.ConfigurationManager . 但是,与此同时,Microsoft通过nuget包System.Configuration.ConfigurationManager将对ConfigurationManager类的支持扩展到.NET核心。

Here are my questions: 这是我的问题:

  • what is the intended best practice to configure .NET core applications ? 配置.NET核心应用程序的最佳实践是什么?
  • the support for app.config file has been implemented only for backward compatibility, so that the porting to .NET core of legacy applications is easier, or it is considered a best practice and it will be maintained in the future ? 对app.config文件的支持是为了向后兼容而实现的,因此将遗留应用程序移植到.NET核心更容易,或者它被认为是最佳实践,并且将来会被维护?

Some history, the original team to begin shrinking the dependencies included in a .Net application was the Asp.Net team. 有些历史,开始缩小.Net应用程序中包含的依赖关系的原始团队是Asp.Net团队。 Microsoft's web framework was bloated compared to more modular frameworks, causing latency in request. 与更多模块化框架相比,微软的Web框架变得臃肿,导致请求延迟。 According to Scott Hansleman whom frequently tells this joke in presentations: 根据Scott Hansleman的说法,他经常在演讲中讲述这个笑话:

Who here develops with .Net? 谁在这里与.Net一起发展? Nobody under thirty, fantastic! 没人在三十岁以下,太棒了! So how do we combat this? 那我们该怎么做呢? Become modular, faster, cross platform, and easier to get started. 变得模块化,更快,跨平台,更容易上手。 Otherwise you would go, I want to learn to code. 否则你会去,我想学习编码。 Download Visual Studio then four hours later write hello world. 下载Visual Studio然后四个小时后写下你好世界。

So the web team began this transformation, which for the web makes JavaScript Object Notation a better choice than Extended Markup Language. 因此,Web团队开始了这种转换,对于Web来说,JavaScript Object Notation比扩展标记语言更好。 But within a year of the Asp.Net team making these modifications Microsoft restructured their organization for a one .Net. 但是,在Asp.Net团队进行这些修改的一年内,微软将其组织重组为一个.Net。 They realized that these changes would cascade across more than just the Asp.Net team. 他们意识到这些变化将不仅仅是Asp.Net团队。 The older project types would not be compatible or work with JavaScript Object Notation, so they transitioned back to Extended Markup for their .csproj and other configuration types. 较旧的项目类型与JavaScript Object Notation不兼容或不兼容,因此它们转换回扩展标记以获取其.csproj和其他配置类型。 But a lot of developers really liked the JavaScript Object Notation files for settings, they are smaller, clearer, and not as verbose. 但是很多开发人员真的很喜欢JavaScript Object Notation文件的设置,它们更小,更清晰,而且不够详细。 So Microsoft added the feature back through Microsoft.Extensions.Configuration to allow you the flexibility. 因此,微软添加了功能回到通过Microsoft.Extensions.Configuration让你的灵活性。

  • The primary purpose was for backwards compatibility. 主要目的是向后兼容。
  • Ensure that it is updated for any .Net Standard application as well. 确保它也适用于任何.Net标准应用程序。

So you can leverage either. 所以你可以利用它们。 No real benefit, aside from Extended Markup tends to be incredibly tedious to read and verbose compare to a JavaScript Object. 除了扩展标记之外,没有真正的好处,与JavaScript对象相比,读取和冗长往往非常繁琐。 JavaScript Object Notation tends to be easier. JavaScript Object Notation往往更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM