[英]How to read value from Appsettings.json for EnableQuery
我想從配置文件中讀取頁面大小。 我試圖進行擴展,但找不到解決方案。 這是我的代碼。
[HttpGet]
[EnableQuery(PageSize = 3)]
public async Task<IEnumerable<users>> Getusers()
{
try
{
var users = await userServices.QueryAll();
}
catch (Exception ex)
{
throw ex
}
}
在您的啟動類中嘗試以下配置:
public Startup(IConfiguration configuration)
{
Configuration = configuration;
[...]
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(config => {
config.Filters.Add(new EnableQueryAttribute() {
PageSize = Configuration["PageSize"]
});
});
}
您需要將相應的條目添加到您的appsettings.json中
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"System": "Information",
"Microsoft": "Information"
}
},
"PageSize": 10
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.