ASP.NET Core 6 Program.csでconfigurationを使用する

ASP.NET Core 6 Program.csでconfigurationを使用する

ASP.NET Core 6 Program.csでconfigurationを使用する順を記述してます。

環境

  • OS windows 10 pro
  • asp.core 6
  • mysql 8.0.27
  • visual stadio 2022

configurationを使用

「Startup.cs」がなくなったので「Program.cs」で「configuration」を使用する手順を記述。

以下のように「builder.Configuration」を使用すれば使用できます。

var builder = WebApplication.CreateBuilder(args);

ConfigurationManager configuration = builder.Configuration;

builder.Services.Configure<FoostoreDatabaseSettings>(
        configuration.GetSection(nameof(HogestoreDatabaseSettings)));