<p>We have a .NET 7 application, that uses autofac IOC and needs to pull RegionInfo from the appsetting file, in a class library that is part of our solution.  When running locally in Visual Studio, or by using Bridge to Kubernetes the IOptions in the class library are populated and the functionality works as expected.  When deployed to our cluster as a docker container though the options are not returned to the class causing the api to fail.</p>
<p>I have spent hours on this trying various suggestions online with autofac with no solution, and I'm hoping that someone can point me in the right direction to resolve this.  Here is the code...</p>
<p>StartUp.cs</p>
<pre><code>        services.AddSwaggerGen(c =&gt;
        {
            c.SwaggerDoc(&quot;v1&quot;, new OpenApiInfo { Title = &quot;IntegrationService&quot;, Version = &quot;v1&quot; });
        });

        services.Configure&lt;RegionInformation&gt;(Configuration.GetSection(&quot;RegionInfo&quot;));
        services.AddOptions();

        var container = new ContainerBuilder();
</code></pre>
<p>GlobalDateManager.cs</p>
<pre><code> private readonly ILogger&lt;GlobalDateManager&gt; _logger;
    private readonly RegionInformation _regionInformation;
   
    public GlobalDateManager(IOptions&lt;RegionInformation&gt; regionInformation, ILogger&lt;GlobalDateManager&gt; logging)
    {
        _regionInformation = regionInformation.Value;
        _logger = logging;
       
    }
</code></pre>

Damian70
<p>I created a simple webapi using part of your code.
It uses the IOptions pattern like your code does, and it outputs the configuration.</p>
<p>It was created launching the simple command <code>dotnet new webapi -o abcde</code></p>
<p>Here the entire files i changed or created:</p>
<p><strong>Program.cs (changed)</strong></p>
<pre class="lang-js prettyprint-override"><code>using Microsoft.OpenApi.Models;
using Autofac;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
var services = builder.Services;

services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
services.AddEndpointsApiExplorer();

// start of your snippet code
services.AddSwaggerGen(c =&gt;
        {
            c.SwaggerDoc(&quot;v1&quot;, new OpenApiInfo { Title = &quot;IntegrationService&quot;, Version = &quot;v1&quot; });
        });
services.Configure&lt;RegionInformation&gt;(builder.Configuration.GetSection(&quot;RegionInfo&quot;));
services.AddOptions();
var container = new  ContainerBuilder(); // added this line of your code: anyway i did not used it in the app
// end of your snippet code

var app = builder.Build();

// Configure the HTTP request pipeline.

app.UseSwagger();
app.UseSwaggerUI();


app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
</code></pre>
<p><strong>RegionInformation.cs (created)</strong></p>
<pre class="lang-js prettyprint-override"><code>public class RegionInformation{

    public const string RegionInfo = &quot;RegionInfo&quot;;

    public string Name {get;set;} = string.Empty;
}
</code></pre>
<p><strong>Controllers/GetConfigAndOptionsController.cs (created)</strong></p>
<pre class="lang-js prettyprint-override"><code>using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace abcde.Controllers;

[ApiController]
[Route(&quot;[controller]&quot;)]
public class GetConfigAndOptionsController : ControllerBase
{   
    private readonly ILogger&lt;GetConfigAndOptionsController&gt; _logger;
    private readonly IConfiguration _configuration;
    private readonly  IOptions&lt;RegionInformation&gt; _regionInformation;

    public GetConfigAndOptionsController(ILogger&lt;GetConfigAndOptionsController&gt; logger, IConfiguration configuration, IOptions&lt;RegionInformation&gt; regionInformation )
    {
        _logger = logger;
        _configuration = configuration;
        _regionInformation = regionInformation;
    }

    [HttpGet(Name = &quot;GetGetConfigAndOptions&quot;)]
    public string Get()
    {
        var sb = new System.IO.StringWriter();
        sb.WriteLine(&quot;Listing all providers (appsettings.json should be present in the list))\n&quot;);
             
        // listing all providers
        foreach (var provider in ((IConfigurationRoot)_configuration).Providers.ToList())
        {
            sb.WriteLine(provider.ToString());
        }    

        // getting the Name using the configuration object
        sb.WriteLine($&quot;\nFrom config: {_configuration[&quot;RegionInfo:Name&quot;]}&quot;);

        // or getting the value using IOption like your code does
        sb.WriteLine($&quot;\nFrom IOptions: {_regionInformation.Value.Name}&quot;);

        return sb.ToString();
    }
}
</code></pre>
<p><strong>appsettings.json (changed)</strong></p>
<pre class="lang-json prettyprint-override"><code>{
  &quot;Logging&quot;: {
    &quot;LogLevel&quot;: {
      &quot;Default&quot;: &quot;Information&quot;,
      &quot;Microsoft.AspNetCore&quot;: &quot;Warning&quot;
    }
  },
  &quot;AllowedHosts&quot;: &quot;*&quot;,
  
  &quot;RegionInfo&quot;:{
    &quot;Name&quot;:&quot;kiggyttass&quot;
  }
}
</code></pre>
<p>Finally i created a simple <strong>Dockerfile</strong></p>
<pre class="lang-yaml prettyprint-override"><code>FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /App

# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /App
COPY --from=build-env /App/out .
ENTRYPOINT [&quot;dotnet&quot;, &quot;abcde.dll&quot;]
</code></pre>
<p>Then,</p>
<pre class="lang-bash prettyprint-override"><code># build your docker image
docker build -t abcde .  

# run it
docker run --name=abcde --rm  -p 9234:80  abcde
</code></pre>
<p>Call the corresponding GET method in the Swagger UI, or cUrl to http://localhost:9234/GetConfigAndOptions</p>
<p>and you should get something like this:</p>
<pre><code>Listing all providers (appsettings.json should be present in the list))

MemoryConfigurationProvider
EnvironmentVariablesConfigurationProvider Prefix: 'ASPNETCORE_'
MemoryConfigurationProvider
EnvironmentVariablesConfigurationProvider Prefix: 'DOTNET_'
JsonConfigurationProvider for 'appsettings.json' (Optional)
JsonConfigurationProvider for 'appsettings.Production.json' (Optional)
EnvironmentVariablesConfigurationProvider Prefix: ''
Microsoft.Extensions.Configuration.ChainedConfigurationProvider

From config: kiggyttass

From IOptions: kiggyttass
</code></pre>
<p>Try to create this dockerized application and check if you get a similar output.
You should get your value using IConfiguration or IOptions.</p>
<p>Hope it helps.</p>
