Skip to content
Sagi edited this page Nov 12, 2015 · 1 revision

Please refer to Multiple Aspects If you haven't read it yet.

Aspects can be prioritized by applying the AspectPriority variable to the aspect attribute.
Lets say that you want to apply two aspects on the same method, the first is of type OnMethodBoundaryAspect and
the second is of type MethodInterceptionAspect.

Please note that by default OnMethodBoundaryAspect has a precedence over MethodInterceptionAspect.

[TransientComposite]
[Mixins(typeof(CSharpDeveloperMixin))]
public interface IDeveloper
{
    [MethodInterceptionAspect(typeof(InterceptionAspectImpl))]
    [OnMethodBoundaryAspect(typeof(OnMethodBoundaryAspectImpl))]
    void Code();
}

The expected output should be:
"OnEntry"
"OnInvoke"
"C# coding"
"OnSuccess"
"OnExit"

By setting the priority using the AspectPriority we can change the order of execution of the aspects:

[TransientComposite]
[Mixins(typeof(CSharpDeveloperMixin))]
public interface IDeveloper
{
    [MethodInterceptionAspect(typeof(InterceptionAspectImpl), AspectPriority = 1)]
    [OnMethodBoundaryAspect(typeof(OnMethodBoundaryAspectImpl), AspectPriority = 2)]
    void Code();
}

Now the expected output should be:
"OnInvoke"
"OnEntry"
"C# coding"
"OnSuccess"
"OnExit"