gpt4 book ai didi

configuration - 如何在 dotnet-isolated (net5.0) azure 函数中使用 IOptions 模式进行配置

转载 作者:行者123 更新时间:2023-12-05 05:59:48 25 4
gpt4 key购买 nike

我正在尝试将现有的 Functions 应用程序从 core3.1 v3 移植到 net5.0 I,但无法弄清楚如何让 IOptions 配置模式工作。

我的 local.settings.json 中的配置存在于配置数据中,我可以使用 GetEnvironmentVariable 获取它。尽管如此,以下内容并未像以前那样将值绑定(bind)到 IOptions 配置。

.Services.AddOptions<GraphApiOptions>()
.Configure<IConfiguration>((settings, configuration) => configuration.GetSection("GraphApi").Bind(settings))

值在 local.settings.json 中,就像以前一样:

    "GraphApi:AuthenticationEndPoint": "https://login.microsoftonline.com/",
"GraphApi:ClientId": "316f9726-0ec9-4ca5-8d04-f39966bebfe1",
"GraphApi:ClientSecret": "VJ7qbWF-ek_Amb_e747nXW-fMOX-~6b8Y6",
"GraphApi:EndPoint": "https://graph.microsoft.com/",
"GraphApi:TenantId": "NuLicense.onmicrosoft.com",

这仍然受支持吗?我错过了什么?

最佳答案

我遇到了同样的问题,但结果是 json 格式不正确

仅供引用,我是这样配置的:

var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(s =>
{
s.AddOptions<ApplicationSettings>().Configure<IConfiguration>((settings, configuration) =>
{
configuration.GetSection(nameof(ApplicationSettings)).Bind(settings);
});
})
.Build();

这里是 local.setting.json 的一个例子:

{
"IsEncrypted": false,
"Values": {
"ApplicationSettings:test": "testtest",
"ApplicationSettings:testtest": "test"
}
}

关于configuration - 如何在 dotnet-isolated (net5.0) azure 函数中使用 IOptions 模式进行配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67964256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com