.net core .Net Core 3.1-Swashbuckler-如何在AddSwaggerGen中使用appsettings

.net core .Net Core 3.1-Swashbuckler-如何在AddSwaggerGen中使用appsettings,.net-core,swagger,.net-core-3.1,swashbuckle.aspnetcore,.net Core,Swagger,.net Core 3.1,Swashbuckle.aspnetcore,我在尝试将AddSwagggerGen扩展中的appsettings用于Swashbuckler的OperationFilter的参数时遇到问题 我尝试过使用ServiceProvider、IConfiguration和前面在startup.cs中定义的预加载DI类 以下是我尝试做的一件事: c.OperationFilter<SwaggerOperationFilter>( this.Configuration.GetSection("ApiSettings&qu

我在尝试将AddSwagggerGen扩展中的appsettings用于Swashbuckler的OperationFilter的参数时遇到问题

我尝试过使用ServiceProvider、IConfiguration和前面在startup.cs中定义的预加载DI类

以下是我尝试做的一件事:

c.OperationFilter<SwaggerOperationFilter>(
    this.Configuration.GetSection("ApiSettings")["MaxResults"]
);

Console.WriteLine(JsonSerializer.Serialize(this.Configuration.GetSection("ApiSettings")) 
>>> {"Key":"ApiSettings","Path":"ApiSettings","Value":null}
c.操作过滤器(
this.Configuration.GetSection(“ApiSettings”)[“MaxResults”]
);
WriteLine(JsonSerializer.Serialize(this.Configuration.GetSection(“ApiSettings”))
>>>{“键”:“ApiSettings”,“路径”:“ApiSettings”,“值”:null}
我可以将
this.Configuration.GetSection(“ApiSettings”)[“MaxResults”]
与硬编码值(如“100”)进行交换,它将正常工作。但我需要从appsettings派生此值,而不是硬编码它

我尝试了很多不同的方法,认为它应该有效,但没有。
我返回的值为null/0,表示该对象为空/新对象。实际上,它没有获得应有的应用程序设置。

Q:您能确切说明什么是“问题”吗?我返回的值为0或value为null,这意味着该对象是空的/新的。它实际上没有获得应有的appsettings。您是否尝试过
this.Configuration.GetSection(“ApiSettings”).GetValue(“MaxResults”)
?这不会有任何好处,因为ApiSettings返回的值为null