У меня есть функция Linux Azure, работающая в .Net 6 (в процессе) v4. У меня есть много настроек, исходящих из
Код: Выделить всё
appsettings.json
Код: Выделить всё
appsettings.json
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
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 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.
Код: Выделить всё
local.json
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"
}
}
Код: Выделить всё
{"Foo":"Test"}
Код: Выделить всё
{"Foo":null}
Код: Выделить всё
{"Foo":"yolo"}
Код: Выделить всё
DummyOption__Foo
Код: Выделить всё
yolo
Кроме того, я добавил следующий код csproj для развертывания
Код: Выделить всё
appsettings.json
Код: Выделить всё
PreserveNewest
true
PreserveNewest
Код: Выделить всё
ConfigureAppConfiguration
Finally, by adding more logs in the
Код: Выделить всё
ConfigureService
Код: Выделить всё
appsettings.json
I am running out of options and would love some help.
Thanks
Источник: https://stackoverflow.com/questions/781 ... 8-isolated