0

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?

Neil Stevens
  • 3,534
  • 6
  • 42
  • 71
  • I haven't tried using Options with isolated functions app, but the configuration values I do use in my function apps all need to reside in the `Values` section. Also, my have necessitated a flat list, so your options would be `"Values": { "MyOptions:XXX": "" }`, etc – peinearydevelopment Feb 17 '23 at 14:21

0 Answers0