i have an issue about extract value from appsetting.json
appsetting.json
"Negozi": {
"PerPage": 10,
"Order": {
"By": "Name",
"Ascending": false,
"Allow": ["Nome", "Citta"]
}
}
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
//useless code for this question
...
//Options
services.Configure<NegoziOptions>(configuration.GetSection("Negozi"));
}
NegoziOptions.cs
public class NegoziOptions
{
public int PerPage { get; set; }
public NegoziOrderOptions Order { get; set; }
}
public class NegoziOrderOptions{
public string By { get; set; }
public bool Ascending { get; set; }
public string Allow { get; set; }
}
}
Then I want to extract data and this is my method
public class EfCoreNegoziService : INegoziService
{
private readonly C3PAWMDbContext dbContext;
private readonly IOptionsMonitor<NegoziOptions> negozioOptions;
public EfCoreNegoziService(C3PAWMDbContext dbContext, IOptionsMonitor<NegoziOptions> negozioOptions)
{
this.negozioOptions = negozioOptions;
this.dbContext = dbContext;
}
public async Task<List<NegozioViewModel>> GetNegoziAsync(string search, int page)
{
search = search ?? "";
page = Math.Max(1, page);
int limit = negozioOptions.CurrentValue.PerPage;
int offset = (page - 1) * limit;
/*
Other code
*/
}
Im trying to debug but this is equals to 0
int limit = negozioOptions.CurrentValue.PerPage;
I have already take data from appsetting.json like ConnectionsStrings and it works fine but i can't understand why I can't extract from Negozi