Assembly-level custom attribute that specifies the execution order of aspects or aspect layers. Define ordering relationships using this attribute to control how aspects compose with each other.
Namespace: Metalama.Framework.Aspects
Assembly: Metalama.Framework.dll
Syntax
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class AspectOrderAttribute : AttributeRemarks
Build-time vs run-time order: Metalama follows the "matryoshka" model—aspects are applied from the inside out at build time, but executed from the outside in at runtime. The build-time order and run-time order are therefore opposite. Use RunTime to specify the more intuitive run-time order, or CompileTime for build-time order.
Partial ordering: You can define partial order relationships using multiple attributes. Metalama merges all relationships from the current project and all referenced projects/libraries using topological sorting. When aspects have no explicit ordering relationship, alphabetical ordering is used for determinism.
Cross-project ordering: Metalama automatically imports aspect order attributes from all referenced projects and assemblies.
You do not need to repeat [assembly: AspectOrder(...)] attributes in projects that use aspects—it is sufficient
to define them once in the projects that define the aspects.
Derived aspects: By default (ApplyToDerivedTypes = true), ordering relationships apply
to derived aspect classes as well. For example, if you order CacheAspect before LoggingAspect, this
also orders MemoryCacheAspect : CacheAspect before FileLoggingAspect : LoggingAspect.
Examples
// Specify run-time order (more intuitive for users)
[assembly: AspectOrder(AspectOrderDirection.RunTime, typeof(CacheAspect), typeof(LoggingAspect), typeof(RetryAspect))]
// Or specify build-time order (more intuitive for aspect authors)
[assembly: AspectOrder(AspectOrderDirection.CompileTime, typeof(RetryAspect), typeof(LoggingAspect), typeof(CacheAspect))]
// These two declarations are equivalent - they both result in the same run-time execution order
Constructors
| Name | Description |
|---|---|
| AspectOrderAttribute(AspectOrderDirection, params string[]) | Initializes a new instance of the AspectOrderAttribute class that specified the order of execution of aspect layers. This constructor allows to specify the order of execution of individual layers. |
| AspectOrderAttribute(AspectOrderDirection, params Type[]) | Initializes a new instance of the AspectOrderAttribute class that specifies the order of execution of aspects. This constructor does not allow multi-layer aspects to overlap each other. If aspects are composed of several layers, all layers of each aspect are ordered as a single group. To order layers individually, use the other constructor. |
| AspectOrderAttribute(params string[]) | |
| AspectOrderAttribute(params Type[]) |
Properties
| Name | Description |
|---|---|
| ApplyToDerivedTypes | Gets or sets a value indicating whether the relationships should apply to derived aspect types. The default value
is |
| Direction | |
| OrderedAspectLayers | Gets the ordered list of aspect layers, in the format specified the constructor documentation. |