小编She*_*dPT的帖子

services.Configure<>() 还是 services.AddSingleton().Get()?

众所周知,有两种方法可以在 ASP.NET Core 2 中获取选项类:

  1. services.Configure<>()像这样使用:

    services.AddOption();
    services.Configure<ApplicationOptions>(Configuration.GetSection("applicationSettings"));
    
    Run Code Online (Sandbox Code Playgroud)
  2. services.AddSingleton(Configuration.Get())像这样使用:

    services.AddSingleton(Configuration.GetSection("applicationSettings")
        .Get<ApplicationOptions>());
    
    Run Code Online (Sandbox Code Playgroud)

但是这些不同的方法有什么优点或缺点?

c# configuration asp.net-core

11
推荐指数
2
解决办法
1万
查看次数

标签 统计

asp.net-core ×1

c# ×1

configuration ×1