ServiceFilter we must register in Startup.cs. TypeFilter is injected by Microsoft.Extensions.DependencyInjection.ObjectFactory, we don\'t need register that filter.
<
Ok, so documentation:
A
ServiceFilterretrieves an instance of the filter from DI. UsingServiceFilterwithout registering the filter type results in an exception.
TypeFilterAttributeis very similar toServiceFilterAttribute(and also implements IFilterFactory), but its type is not resolved directly from the DI container. Instead, it instantiates the type by usingMicrosoft.Extensions.DependencyInjection.ObjectFactory.Because of this difference, types that are referenced using the
TypeFilterAttributedo not need to be registered with the container first (but they will still have their dependencies fulfilled by the container).