title: How can I exclude a controller from ASP.NET Core 3 Attribute Routing
body: <p>I am using ASP.NET Core 3.1 for my web API.  I have multiple controllers all using attribute-based routing and all is well.</p>
  
  <p>We want to be able to toggle one or more controllers with feature flags in the app configuration.  Ideally if a flag is not set then the corresponding controller should cease to exist in the eyes of the API.  I am trying to come up with the best (or any) way to do this.  </p>
  
  <p>There appears to be no built-in way to configure which controllers are scanned when using attribute routing, and no way to modify the collection of controllers or endpoints that the routing finds.  Here is the Startup.cs snippet in question:</p>
  
  <pre><code>    public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
      {            
          app.UseRouting();
          app.UseEndpoints(e =&gt;
          {
              if (!this.FeatureEnabled)
              {
                  // DO SOMETHING?
              }
  
              e.MapControllers();
          });
      }
  </code></pre>
  
  <p>I realize I can probably switch to the more manual hand-written routing and specify every controller, action, and parameter in the Startup class, but I would sooner abandon this feature flag requirement than go down that messy path.</p>
  
  <p>Is there any way to select which controllers are used in the API when using attribute-based routing?</p>