1. 在页面中进行注入配置文件操作
注册对象
class Program { static void Main() { Host.CreateDefaultBuilder().ConfigureWebHostDefaults(builder => builder .ConfigureServices(svcs => svcs .AddSingleton<IFoobar, Foobar>() .AddControllersWithViews()) .Configure(app => app .UseRouting() .UseEndpoints(endpoints => endpoints.MapControllers()))) .Build() .Run(); }
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AppSettings>(_configuration.GetSection("AppSettings")); //注入配置文件
}
}
View视图使用获取注入对象
@inject IFoobar Foobar ; //接口的方式
@inject Microsoft.Extensions.Options.IOptions<Saas.LCI.Admin.Common.AppSettings> _appSettings; //配置文件注入获取
@ { Debug.Assert(Foobar!= null); }
标签:CORE,ASP,Configure,配置文件,app,MVC,NET,注入 From: https://www.cnblogs.com/ksport/p/16914143.html