使用依赖注入的Azure函数ICONFIG
我需要来自配置文件的一些信息,我在我的local.settings.json中有此信息,
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"EmailProcessConnection": "",
"SendDeveloperMails": 0,
"Email": {
"Email": "",
"Password": ""
},
},
"ConnectionStrings": {
"HumanRisksDbContext": ""
}
}
我有一个服务,该服务是从我的时间触发azure函数中调用的。它的构造函数就是这样,
public ControlRisksService(HumanRisksDbContext context,
ILogHandler logHandler, IConfiguration configuration)
{
this.context = context;
_logHandler = logHandler;
_config = configuration;
}
我需要从_config那里获得这样的信息,稍后
_config.GetValue<bool>("SendDeveloperMails")
我该如何获取此信息?
I need some information from config file, I have this information in my local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"EmailProcessConnection": "",
"SendDeveloperMails": 0,
"Email": {
"Email": "",
"Password": ""
},
},
"ConnectionStrings": {
"HumanRisksDbContext": ""
}
}
I have a service which is being called from my time trigger Azure Function. Its constructor is like this
public ControlRisksService(HumanRisksDbContext context,
ILogHandler logHandler, IConfiguration configuration)
{
this.context = context;
_logHandler = logHandler;
_config = configuration;
}
I need to get information from _config like this later on,
_config.GetValue<bool>("SendDeveloperMails")
How can I get this information?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从
local.settings.json
使用emovention Variable
:另外,您需要将更新的
local.settings.json
文件放在中d:\ myApp \ bin \ debug \ net6.0 \ local.settings.json
位置,然后在启动文件中注册JSONprogram.cs
如下:You can get information from the
local.settings.json
usingEnvironmentVariable
:Also, you need to put the updated
local.settings.json
file into theD:\MyApp\bin\Debug\net6.0\local.settings.json
location, and then register the JSON in the startup fileprogram.cs
like below: