IFilterFactory lets an attribute create a filter instance for ASP.NET Core MVC. It combines attribute-based usage with dependency injection for the filter’s services. section 22.3
The framework uses the factory in this sequence:
- Scans controllers and actions when the application loads and builds each action’s filter pipeline. section 22.3
- Calls CreateInstance() when a decorated action runs. section 22.3
- Creates the filter and uses the dependency-injection container to supply dependencies such as RecipeService. section 22.3
- Use TypeFilterAttribute to resolve filter dependencies, or ServiceFilterAttribute to resolve the registered filter itself. section 22.3
Figure 22.3 The framework scans your app on startup to find both filters and attributes that implement IFilterFactory. At runtime, the framework calls CreateInstance() to get an instance of the filter.
The figure shows startup discovery of filters and IFilterFactory attributes followed by runtime calls to CreateInstance(). section 22.3
