Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FeatureGate filter question #341

Open
WeihanLi opened this issue Dec 29, 2023 · 3 comments
Open

FeatureGate filter question #341

WeihanLi opened this issue Dec 29, 2023 · 3 comments
Assignees

Comments

@WeihanLi
Copy link
Contributor

Currently, the FeatureGate is a kind of ActionFilter, should we consider using ResourceFilter or AuthorizationFilter instead, that would be more efficient to avoid some unnecessary flow when feature disabled

public class FeatureGateAttribute : ActionFilterAttribute, IAsyncPageFilter

image

@zhiyuanliang-ms zhiyuanliang-ms self-assigned this Feb 1, 2024
@zhiyuanliang-ms
Copy link
Contributor

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:

  1. Should the stage of "Model Binding" be skipped?
  2. How to implement an Attribute for resource filter?

I need to do more investigation.

@WeihanLi
Copy link
Contributor Author

WeihanLi commented Feb 1, 2024

Thanks for the reply

  1. I think it should be skipped if the feature is not enabled, it seems no need to go through the model binding
  2. Need to inherit the 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 dotnet/aspnetcore#40542

@zhiyuanliang-ms
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants