Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .NET核心设置-最佳实践_C#_.net_Asp.net Core_.net Core_Configuration - Fatal编程技术网

C# .NET核心设置-最佳实践

C# .NET核心设置-最佳实践,c#,.net,asp.net-core,.net-core,configuration,C#,.net,Asp.net Core,.net Core,Configuration,在.NET Framework中,我使用了Properties-settings(Properties.settings.Default.SomeSettingsValue)中的设置。这是非常容易和干净的使用。我现在开始使用.NETCore,但没有类似的设置。我找到了一些解决方案,但没有一个像旧的那样干净简单 对于.NET Core中的设置,最佳做法和解决方案是什么 谢谢。我想您正在寻找 将设置添加到appsettings.json:“设置1”:“测试设置” 创建一个类: 公共类应用程序设置

在.NET Framework中,我使用了Properties-settings(
Properties.settings.Default.SomeSettingsValue
)中的设置。这是非常容易和干净的使用。我现在开始使用.NETCore,但没有类似的设置。我找到了一些解决方案,但没有一个像旧的那样干净简单

对于.NET Core中的设置,最佳做法和解决方案是什么


谢谢。

我想您正在寻找

  • 将设置添加到appsettings.json:“设置1”:“测试设置”
  • 创建一个类:
    
    公共类应用程序设置
    {
    公共字符串设置1{get;set;} }
  • 添加
    services.Configure(配置)到startup.cs
  • 现在,您可以在需要这些选项的类中插入
    IOptions-appSettings
  • 你应该使用。例如,您可以将配置设置添加到appsettings.json文件中,该文件通常在您首次创建项目时自动添加到项目中,例如:

    {
        "Logging": {
            "LogLevel": {
                "Default": "Information"
            }
        },
        "ConnectionStrings": {
            "MyDatabase": "Server=Server1;Database=MyDatabase;Integrated Security=false;",
        },
    }
    

    控制台应用程序怎么样?我不知道,但我找到了。希望有帮助!