WebJobs中的IConfiguration [英] IConfiguration in WebJobs

查看:55
本文介绍了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?

推荐答案

因此您可以将其分配给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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆