If you write code with .NET Core, one day, you will have to configure your application. There is great documentation by Microsoft . here I want to share with you what you really need to write an ordinary application. I’m going to use .NET Core 5. Let’s assume we want to create a simple Web API project. First of all, you have to understand that configuration itself is presented by the interface: IConfiguration public interface IConfiguration { string this[string key] { get; set; } IEnumerable<IConfigurationSection> GetChildren(); IChangeToken GetReloadToken(); IConfigurationSection GetSection(string key); } It is useful to know that an instance of the is already injected in file, and you can use the property to access the whole configuration: IConfiguration Startup.cs Configuration public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } Simple example This might work fine if you need a connection string. Let’s use the file, which is a default setup for the .NET Core Web API application. Here is the code which is generated when you create this type of project: appsetting.json { "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*" } Let’s assume we want to add a connection string section. file could now look like the following. The connection string here is just a sample. You might use the proper one for your database: appsetting.json { "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*", "ConnectionStrings": { "DefaultConnection": "Server=YOURSERVERNAME; Database=YOURDATABASENAME; Trusted_Connection=True; MultipleActiveResultSets=true" } } Now we can access the connection string as follows. Let’s assume we have some class that inherits the interface, and we would like to instantiate it with the connection string from the configuration: UserService IUserService public void ConfigureServices(IServiceCollection services) { var defaultConnectionString = Configuration.GetConnectionString("DefaultConnection"); services.AddScoped<IUserInterface>(x => new UserService(defaultConnectionString)); // another code follows here } Advanced example However, it might be a bit overwhelming to use the whole configuration instance. The better approach is to introduce your own configuration class. Let’s assume you need to integrate a payment system into your application. Here are the steps you need to make. First of all, we need to add a new section to the : PaymentOptions appsettings.json { "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*", "ConnectionStrings": { "DefaultConnection": "Server=YOURSERVERNAME; Database=YOURDATABASENAME; Trusted_Connection=True; MultipleActiveResultSets=true" }, "PaymentOptions": { "Host": "https://host.com", "ApiKey": "hV79DIyA8WEH3AE2N1RDgVDHyEgTPnYC" } } We need to introduce the corresponding C# class: public class PaymentOptions { public string Host { get; set; } public string ApiKey { get; set; } } Now we can inject an instance of the in the file: PaymentOptions Startup.cs public void ConfigureServices(IServiceCollection services) { // another code follows here services.Configure<PaymentOptions>(Configuration.GetSection(nameof(PaymentOptions))); // another code follows here } After that, we can use an instance of the in any class constructor to access payment options through the default dependency injection mechanism. PaymentOptions How to set different values for different environments? By default, and files are created for the new project. It means that you could follow the pattern to create a configuration file for different environments and switch between them. The pattern for the configuration file name is . appsettings.json appsettings.Development.json appsettings.[Environment name].json You can set different values for the configuration properties in different files. To switch between different environment configurations, you have to set the environment variable. ASPNETCORE_ENVIRONMENT How to add a custom JSON file? Sometimes it happens that you need to add a configuration file with the custom name or path. It can be easily done in file. You just need to call method for the instance of . Program.cs ConifugureAppConfiguration() IHostBuilder public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) // attach additional config JSON files .ConfigureAppConfiguration((hostingContext, config) => { config.AddJsonFile("secret/appsettings.secret.json", optional: true); config.AddJsonFile("config/appsettings.json", optional: true, reloadOnChange: true); }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); There are a couple of important things to notice, using property means that if a configuration was changed, the platform would reload it in runtime. Another thing is that the configuration file might be . reloadOnChange optional Summary Configuration of the .NET Core application is very simple and can be done very fast. You have the power of the JSON files to create a configuration in a well-structured format and complete support of the .NET platform to use it in a natural way.