Categories: ASP.NETASP.NET Core

Aspect-oriented programming in .NET Core

Aspect-oriented programming(AOP) is based on Object-oriented programming(OOP) concepts to extend concepts. It separates the main code to record the log messages, fix error messages or other messages recorded in files or other server space, and let the source code coupling level reduce in the project. These log messages can include performance information, event logs, transformation messages, etc. This best example is the filter of the ASP.NET MVC.

It has more third party tools can provide to do, such as PostSharp and Unity. Now, I use Microsoft.Extensions.Logging package to implement AOP in ASP.NET Core project is based on the Onion architecture(Building MVC pattern project by Visual Studio 2017 ( ASP.Net Core Part )). 

In the AOP of the web application project, I will focus on the action filter of the ASP.NET Core and the action filter of the ASP.NET MVC. The action filter default order of execution is from sequence 1 to sequence 6.

SequenceFilter scopeFilter method
1GlobalOnActionExecuting
2Controller or Razor pageOnActionExecuting
3MethodOnActionExecuting
4MethodOnActionExecuted
5Controller or Razor pageOnActionExecuted
6GlobalOnActionExecuted

Microsoft.Extensions.Logging tutorial

Step 1. Create the Logging folder under the web application project. Right-click on the web project -> Add -> New folder.

Fig 1 Create the new folder.

Step 2. Create the two folders under the Logging folder. One folder name is “Interface.” Another folder name is “Repository.”

Fig 2. Create two folder under the Interface folder and the Repository folder.

Page: 1 2 3 4 5

davidsky69

View Comments

Recent Posts

API Gateway in .NET 5 with Ocelot

What is the API gateway? An API gateway is an API management tool that sits…

3 years ago

.NET 5 application with Onion architecture

The .NET 5 SDK is a kind of milestone in the .NET world. The .NET…

3 years ago

SOLID Principles – Dependency inversion principle

In object-oriented design, the dependency inversion principle is a specific methodology for loosely coupling software…

4 years ago

SOLID Principles – Interface segregation principle

In the field of software engineering, the interface segregation principle (ISP) states that no code…

4 years ago

SOLID Principles – Liskov substitution principle

Subtype Requirement: Let  be a property provable about objects  of type T. Then  should be true for objects  of type S where S is…

4 years ago

SOLID Principles – Open-closed principle

In object-oriented programming, the open–closed principle states "software entities (classes, modules, functions, etc.) should be…

4 years ago