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.
Step 8. Edit the InterceptorOfCoreAttribute file that is under the Core project.
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.
Template method – It means the program defines an algorithm skeleton in the superclass, which lets subclasses…
Strategy – It allows the programs to define a family of an algorithm, put each…
State – This pattern can let the program’s object alter its behavior when its internal state changes,…
Observer – It lets the programs define a subscription mechanism to notify multiple objects, which means when…
Null Object – Designed to act as a default value of an object. From Design Pattern –…
Memento – It allows the programs to save and restore the object’s previous state without revealing its…