Open WeihanLi opened 9 months ago
Hi, @WeihanLi
The Feature Management ASP.NET library provides FeatureGateAttribute
and an extension method of AspNetCore.MVC.FilterCollection
called AddForFeature
which will add a FeatureGatedAsyncActionFilter
.
Here what you pointed out is the FeatureGateAttribute
which is built on ActionFilterAttribute
.
The ASP.NET Core includes some built-in filter attributes: ActionFilterAttribute ExceptionFilterAttribute ResultFilterAttribute FormatFilterAttribute ServiceFilterAttribute TypeFilterAttribute
There is no built-in filter attributes for resource filter and authorization filter.
The way to use FeatureGateAttribute
is to place it on MVC controllers, controller actions, or Razor pages.
The FeatureGateAttribute
implements the OnActionExecutionAsync
method which will [run before any of the action's filters]
(https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-8.0#controller-level-filters).
According to the diagram, it seems like the stage of "Model Binding" can be skipped. I don't think using AuthorizationFilter
is sensible.
Therefore, it brings two questions:
I need to do more investigation.
Thanks for the reply
Attribute
to make it work as an attribute and implement the IResourceFilter
/IAuthorizationFilter
or/and the async interface ...I tried to propose an AuthorizationFilterAttribute
like the ActionFilterAttribute
, but seemed the asp.net team does not want to include it in the framework https://github.com/dotnet/aspnetcore/issues/40542
It makes more sense to use resourse filter for the feature gate scenario. I will take a look at your PR and learn how to implement a filter attribute.
Currently, the
FeatureGate
is a kind ofActionFilter
, should we consider usingResourceFilter
orAuthorizationFilter
instead, that would be more efficient to avoid some unnecessary flow when feature disabledhttps://github.com/microsoft/FeatureManagement-Dotnet/blob/e4adec40c8397e0d537bb053aef0e9fc8ed622bf/src/Microsoft.FeatureManagement.AspNetCore/FeatureGateAttribute.cs#L18