AppSettings для AzureFunction в .NET 8 (изолировано)C#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Гость
 AppSettings для AzureFunction в .NET 8 (изолировано)

Сообщение Гость »

Контекст
У меня есть функция Linux Azure, работающая в .Net 6 (в процессе) v4. У меня есть много настроек, исходящих из

Код: Выделить всё

appsettings.json
. Most of these configurations are objects with nested properties or arrays (nothing fancy, but common JSON). Some of these configurations are overridden by the Azure Environment Variable panel (former Configuration panel), especially for connectionStrings or some prod-related settings (expiry timer, etc), but most of the

Код: Выделить всё

appsettings.json
config is default settings to apply on each env.
The problem
I am trying to update the Azure Function to .NET 8. According to the documentation, I have to migrate to the isolated worker model. This is a heavy breaking change and causing a lot of pain, but I can manage that. The real problem is that the

Код: Выделить всё

appsettings.json
config is not loaded anymore (as it used to) when running in Azure. Everything is fine when running locally. I wasted a lot of time trying to get it to load without success. Config is coming nicely from the Azure Environement Variable panel though.
What I don't want to do
  • I don't want to rely solely on the Azure Environment Variable panel as I don't want to replicate and maintain all the default configs in all environments. We have a plan to deploy configuration through bicep templates, but that has much more implications on the overall project infrastructure.
  • I don't want to use the

    Код: Выделить всё

    local.json
    as it is not able to deal with JSON objects or arrays. I would have to flatten all my configs and that would be a mess.
Code sample
I've reproduced the problem in a test project with a dummy setup and am experiencing the same behavior

Код: Выделить всё

Program.cs

Код: Выделить всё

var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureServices((appBuilder, services) =>
{
var configuration = appBuilder.Configuration;

services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();

services.Configure(configuration.GetSection(nameof(DummyOption)));
})
.ConfigureAppConfiguration((hostingContext, configBuilder) =>
{
var env = hostingContext.HostingEnvironment;

configBuilder
.AddJsonFile(Path.Combine(env.ContentRootPath, $"appsettings.json"), optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
})
.Build();

host.Run();

Код: Выделить всё

DummyOption

Код: Выделить всё

public class DummyOption
{
public string Foo { get; set; }
}

Код: Выделить всё

DummyFunction.cs

Код: Выделить всё

    public class DummyFunction
{
private readonly ILogger _logger;
private readonly DummyOption _options;

public DummyFunction(ILogger logger, IOptions options)
{
_logger = logger;
_options = options.Value;
}

[Function("DummyConfig")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req)
{
var json = JsonSerializer.Serialize(_options);
return new OkObjectResult(json);
}
}

Код: Выделить всё

appsettings.json

Код: Выделить всё

{
"DummyOption": {
"Foo": "Test"
}
}
The function returns

Код: Выделить всё

{"Foo":"Test"}
when running locally but

Код: Выделить всё

{"Foo":null}
when running in Azure. The function returns

Код: Выделить всё

{"Foo":"yolo"}
if I add a

Код: Выделить всё

DummyOption__Foo
= in the Azure Envrionement panel, but again I dont want to do that. Это будет сложно поддерживать и масштабировать.
Кроме того, я добавил следующий код csproj для развертывания

Код: Выделить всё

appsettings.json
file with the build, and confirmed the file exist next to the DLL in the Function App files.

Код: Выделить всё

      
PreserveNewest
true
PreserveNewest

I even confirmed the file exists, and is accessible by adding some logs in

Код: Выделить всё

ConfigureAppConfiguration
.
Finally, by adding more logs in the

Код: Выделить всё

ConfigureService
, I can see the

Код: Выделить всё

appsettings.json
config is just not loaded in the configuration at all.
I am running out of options and would love some help.
Thanks


Источник: https://stackoverflow.com/questions/781 ... 8-isolated
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • AppSettings для AzureFunction в .NET 8 (изолировано)
    Гость » » в форуме C#
    0 Ответы
    16 Просмотры
    Последнее сообщение Гость
  • AppSettings для AzureFunction в .NET 8 (изолировано)
    Anonymous » » в форуме C#
    0 Ответы
    11 Просмотры
    Последнее сообщение Anonymous
  • AppSettings для AzureFunction в .NET 8 (изолировано)
    Anonymous » » в форуме C#
    0 Ответы
    5 Просмотры
    Последнее сообщение Anonymous
  • Можем ли мы использовать один файл appsettings.json вместо поддержки нескольких версий appsettings.{environmentname}.jso
    Anonymous » » в форуме C#
    0 Ответы
    40 Просмотры
    Последнее сообщение Anonymous
  • Перемотка неудачного экземпляра функции Azure Durable (изолировано)
    Anonymous » » в форуме C#
    0 Ответы
    15 Просмотры
    Последнее сообщение Anonymous

Вернуться в «C#»