本文介绍了WebJobs中的IConfiguration的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ASP.NET Core WebJobs项目,该项目正在使用ASP.NET Core Web应用程序中的类库.
I have an ASP.NET Core WebJobs project that is using class libraries from an ASP.NET Core web app.
在Web应用程序中,我只是使用IConfiguration来访问我的所有设置.在我的WebJobs应用程序中,我有以下几行似乎使用了IConfigurationRoot.
In the web app, I'm simply using IConfiguration to access all my settings. In my WebJobs app, I have the following lines which appear to use IConfigurationRoot.
var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build();那么,如何从IConfigurationRoot转到IConfiguration?
推荐答案IConfigurationRoot 源自IConfiguration
public interface IConfigurationRoot : Microsoft.Extensions.Configuration.IConfiguration因此您可以将其分配给IConfiguration变量
So you can assign it to an IConfiguration variable
IConfiguration configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build();更多推荐
WebJobs中的IConfiguration
发布评论