Last active
April 8, 2022 22:41
-
-
Save rodion-m/17262b7a5384b6b16898b2bb55c0c07b to your computer and use it in GitHub Desktop.
An example of filter ordering based on enum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AppAuthFilterAttribute : Attribute, IAuthorizationFilter, IAppOrderedFilter | |
{ | |
public FilterOrder Order { get; set; } | |
public void OnAuthorization(AuthorizationFilterContext context) | |
{ | |
//some logic... | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just an example of using AppAuthFilter ordering with controller | |
[AppAuthFilter(Order = FilterOrder.AppAuthFilter1)] | |
public class OrderController : ControllerBase | |
{ | |
[HttpGet] | |
public IActionResult Index() | |
{ | |
return Ok(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum FilterOrder | |
{ | |
AppAuthFilter1 = 1, MyAuthFilter2 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IAppOrderedFilter : IOrderedFilter | |
{ | |
new FilterOrder Order { get; set; } | |
int IOrderedFilter.Order => (int) Order; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment