title: Custom Attribute settings in .net Core
body: <p>I am writing a very simple custom attribute to be used with my methods for ASP.net Core.  The attribute is to handle feature flags which indicate an endpoint method is "switched on or off" as follows:</p>
  
  <p>1) If a feature is turned ON, allow the code to pass through to the method and execute it as normal.
  2) If the feature is turned OFF, just return from the attribute and dont execute the method within</p>
  
  <p>I was thinking something along the lines of this:</p>
  
  <pre><code>[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
  public class FeatureFlagAttribute : ActionFilterAttribute
  {
      private Dictionary&lt;string, bool&gt; myFeaturesList;
      private readonly string selectedFeature;
  
      public FeatureFlagAttribute(string featureName)
      {
          selectedFeature = featureName;
      }
  
      public override void OnActionExecuting(ActionExecutingContext context)
      {
          var found = myFeaturesList.TryGetValue(selectedFeature, out var result);
  
          if (!found || !result)
          {
              // dont continue
              context.HttpContext.Response.StatusCode = 403;
          }
      }
  }
  </code></pre>
  
  <p>I need the <code>myFeaturesList</code> populated for this to work BUT I dont want to pass it into the constructor every time this is being used. Whats the best way to configure this?  I was thinking of setting a static property in the attribute but thought this was a bit of a lame approach and that there must be a better way.  Thanks in advance!</p>