title: access middleware options when invoke
body: <p>I'm creating a custom middleware element but can't figure out how to pass on the Options object to the middleware and access them in the Invoke method.</p>
  
  <p><strong>Config</strong>:</p>
  
  <pre><code>public class MiddleConfig
  {
      private readonly ICollection&lt;string&gt; _c;
  
      public MiddleConfig()
      {
          _c = new Collection&lt;string&gt;();
      }
  
      public void AddPath(string path)
      {
          _c.Add(path);
      }
  
      public IEnumerable&lt;string&gt; Paths =&gt; _c;
  }
  </code></pre>
  
  <p><strong>MiddleConfig</strong>:</p>
  
  <pre><code>public class Middle
  {
      private readonly RequestDelegate _next;
      private readonly MiddleConfig _opt = new MiddleConfig();
  
      public Middle(RequestDelegate next, MiddleConfig options)
      {
          _opt = options;
          _next = next;
      }
  
      public async Task Invoke(HttpContext context)
      {
          await _next.Invoke(context);
      }
  }
  </code></pre>
  
  <p><strong>Extension</strong>:</p>
  
  <pre><code>public static IServiceCollection AddLCPathControl(this IServiceCollection services, Action&lt;MiddleConfig&gt; options)
  {
      MiddleConfig opt = new MiddleConfig();
      options.Invoke(opt);
  
      return services.AddScoped&lt;Middle&gt;();
  }
  </code></pre>