配置文件的读取和使用
var configModel = configuration.GetSection("DataBaseConfig").Get<DataBaseConfigModel>();
services.Configure<AssemblyConfig>(configuration.GetSection("AssemblyConfig"));
.net core3.1
public class Startup
{
public Microsoft.Extensions.Configuration.IConfiguration Configuration { get; }
public Startup(Microsoft.Extensions.Configuration.IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
}
}
.net 6
var builder = WebApplication.CreateBuilder(args);
ConfigurationManager configuration = builder.Configuration;
var env = builder.Environment;
var imServerSetting = configuration.GetSection("Option").Get<ServerConfigOptions>();
var app = builder.Build();
app.Run();