title: Can I use C# 9 records as IOptions?
body: <p>I have just started playing around with C# 9 and .NET 5.0, specifically the new <code>record</code> construct. I find I have a lot of excellent use cases for the shorthand syntax of the record types.</p>
  <p>One of the use cases I've considered was using a <code>record</code> for the dto in <code>IOptions&lt;&gt;</code>, instead of regular classes, for ASP.NET Core applications. These option classes are usually quite plain so I thought it would be a perfect fit, but it seems I cannot get it to work easily, since configuring the application using <code>IOptions&lt;&gt;</code> requires the object to have a parameterless constructor.</p>
  <pre class="lang-cs prettyprint-override"><code>public record MyOptions(string OptionA, int OptionB);
  
  public class Startup
  {
      public void ConfigureServices(IServiceCollection services) {
          services.Configure&lt;MyOptions&gt;(Configuration.GetSection(nameof(MyOptions)));
      }
  ...
  }
  
  public class MyController : Controller 
  {
      private readonly MyOptions _options;
      public MyController(IOptions&lt;MyOptions&gt; options) {
          _options = options.Value;  // This throws an exception at runtime
      }
  }
  
  </code></pre>
  <p>The example above throws the following exception when attempting to access the <code>IOption&lt;&gt;.Value</code> property:</p>
  <blockquote>
  <p>System.MissingMethodException: 'No parameterless constructor defined for type 'AcmeSolution.MyOptions'.'</p>
  </blockquote>
  <p>Is there any way to configure the <code>IOptions</code> configuration system to deserialize the options using the record's constructor instead of requiring a parameterless constructor?</p>
  <p>I could use the longhand syntax for the records, but then there's really no benefit over using a class.</p>