I’m just trying to apply Option Pattern and I coded that in ConfigureServices:
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
However VS gives the error “The name Configuration does not exist in the current context.”
I added almost all the namespaces such as using System.Configuration and using Microsoft.Extensions.Configuration. Closed the VS and opened it again. Delete the code and coded again but still I get the same error and Configuration is always highlighted with red.
Do you know what’s going on here?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Here Configuration is a property. You need to add
private readonly IConfiguration Configuration { get; set;}
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0