(E) .NET Core Filter the filter on the use

Knowledge Point Review:

Previous articles are to introduce the

(1) Swagger integration and usage;

(2) JWT authentication integration and usage;

(3) OOM object mapping framework AnutoMapper usage;

Today to introduce the basic use of a filter Filter:

What is the role of the filter, it is suitable to use under what scenario?

Suppose a project progress to the end of the time, the project leader in order to ensure stability and monitoring and maintenance of the program requires that all methods plus the log, if the project is relatively large, the method is very large, it would not have to charge a lot too strength to accomplish such a thing. But do not worry, ye have encountered problems, language designers had the great help we want a good solution to the filter, the filter is an AOP (Aspect Oriented Programming) technology embodies, AOP has a loose coupling, easy to expand, characteristics with reusable code.

Usually we as authentication, logging in these scenarios, the exception will be used to acquire and other filters

The .NET Core filter life cycle:

(E) .NET Core Filter the filter on the use

.NET Core in a variety of filters, today to introduce the main usage of ActionFilterAttribute

(1) a custom Filter class:

(E) .NET Core Filter the filter on the use

(2) register the filter, the filter registered in two ways, one is a global register, and the other is a local register:
(E) .NET Core Filter the filter on the use

Local registration, local registration may be embodied on a class or method:
(E) .NET Core Filter the filter on the use

(3) operation, requesting a particular interface tracking about the execution order:

(E) .NET Core Filter the filter on the use

(E) .NET Core Filter the filter on the use

Can be seen that the filter functions corresponding role.

Guess you like

Origin blog.51cto.com/14465598/2447871