Categories: ASP.NETASP.NET MVC

Extended Aspect-Oriented Programming (AOP) in .NET MVC

Step 4. Create the “Interceptor” folder under the Infra project and the Core project, then create two class files under the Infra project’s Interceptor folder and the Core project’s Interceptor folder.

One file name sets “InterceptorHandler.” Another file name sets “InterceptorOfCoreAttribute” or “InterceptorOfInfraAttribute.”

Step 5. Edit the InterceptorHandler file that is under the Core project. Let the InterceptorHandler inherits the ImessageSink interface class, then creating the synchronous process messages function and the asynchronous process message method.

Fig 6 Core project’s InterceptorHandler class file source code

Now, I develop this demo web application project that will focus on the SysncProcessMessage method and won’t focus on the asynchronous process message method because the demo project is the sample project concept. If you want to use the asynchronous process message method and don’t want to use the synchronous process message method, it will be O.K. If you wish only to use the synchronous process message method, it will be O.K. If you consider a complex web project or the huge web project, you must carefully consider the intercept mechanism in your project. Maybe it brings to the performance problems that aren’t about the hardware, the IIS server, etc. It is about software architecture’s design pattern problems.

Note: If you want to see the complete source code about the InterceptorHandler class file, please, click my GitHub repository.

Step 6. Edit the InterceptorOfCoreAttribute file that is under the Core project’s Interceptor folder. The InterceptorOfCoreAttribute class file inherits the ContextAttribute class file and the IContributeObjectSink interface file. Remember, the layer string variable must write this layer name. After the web application is running, the log information will show in your log file or on Visual Studio’s Output view.

Fig 7. Core project’s InterceptorOfCoreAttribute file source code
public class InterceptorOfCoreAttribute : ContextAttribute, IContributeObjectSink
{
 private readonly string layer = "Enterprise_MVC_WebApplication.Core";

 public InterceptorOfCoreAttribute() : base("InterceptorOfCoreAttribute") { }


 public IMessageSink GetObjectSink(MarshalByRefObject obj, IMessageSink nextSink)
 {
  return new InterceptorHandler(this.layer, nextSink);
 }
}

Page: 1 2 3 4 5

davidsky69

Recent Posts

SOLID Principles – Single-responsibility principle

The single-responsibility principle (SRP) is a computer-programming principle that states that every module, class or…

4 years ago

Microservices – Command and Query Responsibility Segregation(CQRS)

Command query responsibility segregation (CQRS) generalizes CQS to message-driven and event-driven architectures: it applies the CQS…

4 years ago

Microservices – Domain-driven design(DDD)

Domain-driven design (DDD) is a software design approach focusing on modelling software to match a…

4 years ago

Microservices – Onion architecture

A microservice architecture – a variant of the service-oriented architecture (SOA) structural style – arranges…

4 years ago

Unit Of Work pattern concepts in .NET

The Repository pattern and Unit of Work pattern are used together in most time. Unit…

4 years ago

Behavioral Patterns – Visitor

Visitor – It allows the program changes the algorithm and the operations that base on the visitor…

4 years ago