This section will show some concrete use cases for filters. In general, each time you have to replicate the behavior in an action or a controller, you can use filters to centralize the logic. Filters also provide a declarative approach, which helps us keep your code clean and readable.
Filter use cases
Existing entity constraints
Action methods of controllers usually perform constraints on incoming data. A common practice is to centralize that kind of logic in filters. Let's take, for example, OrderController, which we discussed in the previous chapter:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.Mvc;
using SampleAPI.Filters;
using SampleAPI...