配置文件如何注册引用
注册配置文件的形式
注册方式
// 第一种注册方式:注册配置文件
builder.Services.Configure<AppSettings>(builder.Configuration.GetSection("AppSettings"));
AppSettings appSettings = builder.Configuration.GetSection(AppSettings.Key).Get<AppSettings>()!;
Console.WriteLine(appSettings.Port);
Console.WriteLine(appSettings.ConnectionString);
使用方式
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace AspDemo.Server.Controllers;
[ApiController]
[Route("[controller]")]
public class AppSettingTwoController : ControllerBase
{
//
标签:asp,Console,WriteLine,配置文件,appSettings,注册,AppSettings,net
From: https://www.cnblogs.com/zhuoss/p/18398416