services.AddMvc(options => { options.Filters.Add(new MyCustomFilter()); });
public void ConfigureServices(IServiceCollection services) { services.AddControllers(options => { options.Filters.Add(new MyCustomFilter()); }); }In this example, we are adding a custom filter to the collection that will be applied to all requests handled by the Controllers in the application. The GlobalFilterCollection class is part of the Microsoft.AspNetCore.Mvc.Filters namespace and is included in the Microsoft.AspNetCore.Mvc.Core package.