Overview

It is quite often the case that an aspect cannot be expressed as a single of the atomic aspects. For instance, implementing the INotifyPropertyChanged interface requires one Composition aspect, and as many On Method Boundary aspects as there are writable properties.

Compound aspects offer an elegant way to group atomic aspects together in order to implement a more complex aspect. These atomic aspects composing a compound aspect are said sub-aspects.

You can develop a compound aspect by deriving a new class from the CompoundAspect class or the ICompoundAspect. But actually, any atomic aspect can be turned into a compound aspect by implementing the ILaosReflectionAspectProvider interface.

Compound aspects implement the ProvideAspects method, which should add sub-aspects to the collection provided as an argument. Note that the sub-aspects you provide using this methods do not need to be custom attributes. It is enough if they implement any of the aspect interfaces.

Initialization of sub-aspects

The PostSharp Laos does not automatically initialize the sub-aspects by calling a CompileTimeInitialize. Any initialization, if necessary, should be done in the ProvideAspects method or in the constructor of sub-aspects.

However, sub-aspects are initialized at runtime just like normal aspects using the RunTimeInitialize method.

Graphs of aspects

It is common that sub-aspects of a compound aspect form an object graph. For instance, sub-aspects may contain a reference to the compound aspect.

An interesting feature of compound aspects and of PostSharp Laos is that object graphs instantiated at compile-time are serialized, and can be used at run-time. In other words, if you store in a sub-aspect a reference to another sub-aspect, you will be able to use this reference at runtime.