在.NET Core测试项目中读取appsettings json值
我的Web应用程序需要从appsettings.json文件读取Document DB密钥。我创建了一个具有键名的类,并以如下方式读取Config部分ConfigureaServices(): public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); Configuration = builder.Build(); } public IConfigurationRoot Configuration { get; } public void ConfigureServices(IServiceCollection services) { services.AddMvc().AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()); services.AddSession(); Helpers.GetConfigurationSettings(services, Configuration); DIBuilder.AddDependency(services, Configuration); } 我正在寻找在测试项目中读取键值的方法。