Categories: ASP.NETASP.NET MVC

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

Step 7. Edit the InterceptorHandler file that is under the Infra project. The InterceptorHandler inherits the IMessageSink interface. It is the same as the Core project’s InterceptorHandler file. The source code part is also the same without any different factors. In the Infra project, we keep focusing on the synchronous process message method. You can find out my sample asynchronous process message method returns the null value.

Fig 8. Infra project’s InterceptorHandler file source code

Step 8. Edit the InterceptorOfCoreAttribute file that is under the Core project.

Fig 8. Infra project’s InterceptorOfInfraAttribute file source code
public class InterceptorOfInfraAttribute: ContextAttribute, IContributeObjectSink
{
 private readonly string layer = "Enterprise_MVC_WebApplication.Infra";

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

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

You can find the InterceptorHandler file source code without any different parts in the Core project and the Infra project because the two functions are the same. The only additional part is file path difference and under difference project, because it intercepts difference layer information.

Note: From step 5 to step 8, most of part source code is as same. A few parts have a little difference. All aspect-oriented programming log information won’t write to the log file. I will use the Debug.WriteLine method to show intercept log messages. You can use the NLog Nuget package or the log4net Nuget package to record the intercept log messages in your web application project.

Page: 1 2 3 4 5

davidsky69

Recent Posts

Behavioral Patterns – Template method

Template method – It means the program defines an algorithm skeleton in the superclass, which lets subclasses…

4 years ago

Behavioral Patterns – Strategy

Strategy – It allows the programs to define a family of an algorithm, put each…

4 years ago

Behavioral Patterns – State

State – This pattern can let the program’s object alter its behavior when its internal state changes,…

4 years ago

Behavioral Patterns – Observer

Observer – It lets the programs define a subscription mechanism to notify multiple objects, which means when…

4 years ago

Behavioral Patterns – Null Object

Null Object – Designed to act as a default value of an object. From Design Pattern –…

5 years ago

Behavioral Patterns – Memento

Memento – It allows the programs to save and restore the object’s previous state without revealing its…

5 years ago