If you want to avoid the Locator service pattern, you can use DI by injecting the constructor using TypeFilter .
In your controller use
[TypeFilter(typeof(MyActionFilterAttribute), Arguments = new object[] {10})] public IActionResult() NiceAction { ... }
And your ActionFilterAttribute no longer needs to access the service provider instance.
public class MyActionFilterAttribute : ActionFilterAttribute { public int Limit { get; set; }
For me, the annotation [TypeFilter(typeof(MyActionFilterAttribute), Arguments = new object[] {10})] seems uncomfortable. To get a more readable annotation, for example [MyActionFilter(Limit = 10)] , your filter should inherit from TypeFilterAttribute . My answer How do I add a parameter to an action filter in asp.net? shows an example of this approach.
Ralf bΓΆnning
source share