0

Is it possible to use Feature Toggling in MVC Web APIs?

I want to restrict certain controller actions to be called until the API functionality is complete.

Rockstart
  • 2,337
  • 5
  • 30
  • 59

1 Answers1

1

A suggestion could be to create a custom Feature actionfilter. Maybe like this:

public class FeatureAttribute : ActionFilterAttribute
{
    public string RequiredFeature { get; set; }
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        if (!Settings.Default.SomeFeature)
        {
            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {{ "Controller", "Home" }, { "Action", "Index" } });
        }
        base.OnActionExecuting(filterContext);
    }
}

And on your controller add the attribute:

[Feature(RequiredFeature = "Somefeature")]
public ActionResult ActionNotYetReady()
{
    return View();   
}

This is a simple example, but would redirect users to a specific controller-action whenever the feature toggle/config setting for a given feature is turned off.

Indregaard
  • 1,195
  • 1
  • 18
  • 26