Nucleus.mockaop.net:OpenSource .NET AOP Framework

xiaoxiao2021-03-06  28

Introduction to Nucleus.MockAop.net

First, function

Based on the configuration file, dynamically load aspects to different classes, specify different aspects (based on regular expressions or inheritance relationships), specifying different Aspects (based on regular expressions) specifying the relative execution order of Aspects for ASPECTS. A CHAINOFRESPONSBILITY mode of RealProxy implementation, and provides the framework of the Aspect required for this RealProxy, and three sample aspect, used to calculate execution time, print input parameters, and return values, and capture all exceptions.

Second, restriction

Did not find a good way to become stateless, resulting in a normal object every New, will be included with a number of Aspect objects, the performance affected does not find a good way to find the most flexible configuration class, the method is associated with Aspect, now the configuration information is scattered throughout Increase the coupling between the objects, the burden of the Aspect object, as each Aspect object is now determined whether the currently called the original method in which the configuration is matched in the configuration file, if the match is cut, otherwise ignored ignored Dynamic configuration of RealProxy has not yet implemented (ie different proxy strategies)

Third, use

The class that will be hoped into the aspect (ie, the class is managed by the AOP) is derived from numberus.mockaop.aspectManageDObject, and the class and its subclasses will be managed by AOP; if a separate subclass wants to leave management, the declaration will declare AspectManaged property is set to false

Nucleus.MockAOP.AspectManagedObject defined namespace Nucleus.MockAOP {[AspectManaged] public class AspectManagedObject: ContextBoundObject {}} wishing AOP management class definition public class SomeBusinessClass: AspectManagedObject {public string SomeProperty {get {return "pone";}}} Parent Class is managed by AOP, some subclasses want to be separated from AOP management [AspectManaged (false)] public class somefreeclass: businessclass {}

IASPECT interface

IAspect defined namespace Nucleus.MockAOP {public interface IAspect {IMethodReturnMessage SyncExecuteMethod (IMethodCallMessage msg); IConstructionReturnMessage SyncExecuteConstructor (IConstructionCallMessage msg);}} define new Aspect public class TerminatorAspect: IAspect {#region IAspect members of the public IMethodReturnMessage SyncExecuteMethod (IMethodCallMessage msg) {return xxx;} public IConstructionReturnMessage SyncExecuteConstructor (IConstructionCallMessage msg) {return xxx;} #endregion} RealProxy ChainOfResponsbility defined patterns to achieve cooperation Aspect public class ExceptionAspect: BaseChainNodeAspect {protected override IMethodReturnMessage xxxxxx (IMethodCallMessage msg) {return xxx;}} in the configuration The relative execution order of Aspects and Aspects is specified for class and methods; use regular expressions (type_name_regex) or inheritance relationship (instance_of), when used in the same type_name_pattern, TYPE_NAME_REGEX is subject to

-

<

CONFIGURATION

>

-

<

Configsections

>

<

section

Name

= "

AOP_SETTING

"

Type

= "

Nucleus.mockaop.aspectconfighandler, Nucleus.MockAop

"/>

Configsections

>

-

<

AOP_SETTING

>

-

<

TYPE_NAME_PATTERN TYPE_NAME_REGEX

= "

Nucleus.mockaop.test.businessClass

">

<

Aspect

Type

= "

Nucleus.mockaop.aspectschainimpl.durationaspect

"

Method_name_Regex

= "

(-) *

"

ORDER

= "

10

"/>

<

Aspect

Type

= "

Nucleus.mockaop.AaspectSchainImpl.MethodInfoaspect

"

Method_name_Regex

= "

GetString

"

ORDER

= "

20

"/>

<

Aspect

Type

= "

Nucleus.mockaop.aspectschainimpl.exceptionAmect "

ORDER

= "

30

"/>

TYPE_NAME_PATTERN

>

-

<

TYPE_NAME_PATTERN INSTANCE_OF

= "

Nucleus.mockaop.test.ibusiness, Nucleus.Mockaop.Test

">

<

Aspect

Type

= "

Nucleus.mockaop.aspectschainimpl.durationaspect

"

Method_name_Regex

= "

(-) *

"

ORDER

= "

10

"/>

<

Aspect

Type

= "

Nucleus.mockaop.AaspectSchainImpl.MethodInfoaspect

"

Method_name_Regex

= "

GetString

"

ORDER

= "

20

"/>

<

Aspect

Type

= "

Nucleus.mockaop.AaspectSchainImpl.ExceptionAmect

"

ORDER

= "

30

"/>

TYPE_NAME_PATTERN

>

-

<

TYPE_NAME_PATTERN TYPE_NAME_REGEX

= "

(Class / * not / * exist) {1}

">

<

Aspect

Type

= "

Nucleus.mockaop.aspectschainimpl.durationaspect

"

ORDER

= "

10

"/>

<

Aspect

Type

= "

Nucleus.mockaop.AaspectSchainImpl.MethodInfoaspect

"

ORDER

= "

20

"/>

TYPE_NAME_PATTERN

>

AOP_SETTING

>

CONFIGURATION

>

Fourth, download communication

Temporarily in the website of XPDL_Parser: Nucleus.mockaop.net is very far away, I hope to give education

Five, reference materials

JGTM'2004 .NET blog AOP framework in WebSharp

转载请注明原文地址:https://www.9cbs.com/read-81926.html

New Post(0)