IConfiguration in WebJobs

喜欢而已 提交于 2019-12-24 11:12:14

问题


I have an ASP.NET Core WebJobs project that is using class libraries from an ASP.NET Core web app.

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();

So, how do I go from IConfigurationRoot to IConfiguration?


回答1:


IConfigurationRoot is derived from IConfiguration

public interface IConfigurationRoot : Microsoft.Extensions.Configuration.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();


来源:https://stackoverflow.com/questions/51883542/iconfiguration-in-webjobs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!