public void ConfigureServices(IServiceCollection services) { var configBuilder = new ConfigurationBuilder() .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "Config")) .AddJsonFile("pay.json", optional: false, reloadOnChange: true); Configuration = configBuilder.Build(); services.Configure<PayOptions>(Configuration.GetSection("PayOptions")); ServiceProvider provider = services.BuildServiceProvider(); PayOptions value = provider.GetRequiredService<IOptions<PayOptions>>().Value; PayOptions = value; services.AddControllers(); }
标签:core,自定义,配置文件,PayOptions,configBuilder,provider,services From: https://www.cnblogs.com/changsen-wang/p/17524468.html