Summary of using dependency injection knowledge points in asp.net core filter

Time:2020-5-9

How to use constructor injection for actionfilterattribute?

The general custom filter can be used directly by identifying the characteristics

[ContentFilter]

Because the constructor requires parameters when it is used, then we can use this

ServiceFilter

In asp.net core, we can use servicefilter to fulfill this requirement.

Servicefilter allows us to parse a service with IOC container added, so we need to register contentfilter.

services.AddScoped<ContentFilter>();

Identify directly with features where needed

[ServiceFilter(typeof(ContentFilter))]

Then it is found that it can be instantiated and used

That’s all the knowledge in this introduction. Thank you for your learning and support for developepaer.