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
ServiceFilter
retrieves an instance of the filter from DI. UsingServiceFilter
without registering the filter type results in an exception.
TypeFilterAttribute
is 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
TypeFilterAttribute
do not need to be registered with the container first (but they will still have their dependencies fulfilled by the container).