Home > OS >  In Visual studio 2022, How To add IConfiguration and add configuration in Program.cs like startup.cs
In Visual studio 2022, How To add IConfiguration and add configuration in Program.cs like startup.cs

Time:11-29

enter image description hereI need to add a configuration and to customize accordingly. In before versions in the startup.cs there is a class specifically for configuration. I need to know how to add configuration in program.cs

In before versions in the startup.cs there is a class specifically for configuration. I need to know how to add configuration in program.cs

CodePudding user response:

IConfiguration interface is located in Microsoft.Extensions.Configuration namespace. You could install Microsoft.Extensions.Configuration nuget, and get access to IConfiguration interface.

CodePudding user response:

You can get the configuration like so:

IConfiguration configuration = builder.Configuration;

CodePudding user response:

We can do this:

    var builder = WebApplication.CreateBuilder(args);
    //Get the instance of the IConfiguration service
    var configuration = builder.Configuration;
    //We can configure configuration variables of type IConfiguration and get a value 
    var vTestValue = configuration.GetValue<string>("TestValue");
  • Related