I have a really simple Azure Function using the dotnet-isolated runtime but having some issues with the dependency injection setup, specifically around the IOptions
pattern, my code is as follows
var host = new HostBuilder()
.ConfigureAppConfiguration(c =>
{
c.AddJsonFile("local.settings.json", true);
})
.ConfigureFunctionWorkerDefaults((context, builder) =>
{
})
.ConfigureServices((builder, services) =>
{
services.AddOptions();
services.Configure<MyOptions>(options =>
{
builder.Configuration.GetSection("MyOptions").Bind(options); // this doesn't get called
});
})
.Build();
host.Run();
Local app settings file then as the following
{
"IsEncrypted": false,
"Values": {
...
},
"MyOptions": {
...
}
}
My issue is when running the function app the .Configure
action is never called, you can set a breakpoint on that line and the breakpoint is never hit. This works in the old webjobs and I know this is the dotnet core way to do it, but for some reason my code is never executed.
So does the IOptions
pattern still work in dotnet-isolated function and what am I missing/doing wrong here?