How it works...

ServiceFilterAttribute is the way with ASP.NET Core to inject filters that have dependencies in the constructor. If we do not use ServiceFilterAttribute to use filter attributes, they will be managed automatically by ASP.NET Core.

There are differences between the TypeFilter attribute and the ServiceFilter attribute. With TypeFilter, the filter type in the parameter will be resolved by the ObjectFactory class. With ServiceFilter, the filter type in the parameter will be resolved by the internal DI container.

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.