title: How can Autofac and an Options pattern be used in a .NET 5 console application?
body: <p>I am trying to use an option pattern with Autofac and every attempt has just resulted in errors.</p>
  <p>What I've tried:</p>
  <ol>
  <li>Using the ConfigurationBuilder to retrieve an IConfiguration/IConfigurationRoot.</li>
  <li>Register an instance of <code>TestSectionOptions</code> using the IConfiguration/IConfigurationRoot that was created before:
  <code>builder.Register(c =&gt; config.GetSection(&quot;TestSection&quot;).Get&lt;TestSectionOptions&gt;());</code></li>
  <li>Trying to inject it via constructor injection:</li>
  </ol>
  <pre class="lang-cs prettyprint-override"><code>private readonly TestSectionOptions _options;
      
  public DemoClass(IOptions&lt;TestSectionOptions&gt; options)
  {
      _options = options.Value;
  }
  </code></pre>
  <p>I'm getting following error:</p>
  <blockquote>
  <p>DependencyResolutionException: None of the constructors found with
  'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type
  'DemoApp.DemoClass' can be invoked with the available services and parameters:
  Cannot resolve parameter
  'Microsoft.Extensions.Options.IOptions<code>1[DemoApp.TestSectionOptions] options' of constructor 'Void .ctor(Microsoft.Extensions.Options.IOptions</code>1</p>
  </blockquote>
  <p>Of course I tried other types of registration, but none of them worked.
  I also know that I can simply bind the configuration file to a class, which I then register and inject without the IOptions&lt;&gt; part. But that would no longer correspond exactly to the option pattern, would it?
  Even if it doesn't make a big difference, I'd still like to know why it doesn't work and how I could get it to work.</p>