WebJobs中的IConfiguration

编程入门 行业动态 更新时间:2024-10-28 16:22:24
本文介绍了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

本文发布于:2023-11-14 21:43:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1588573.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WebJobs   IConfiguration

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!