Class ProtoCompositeAttribute
An attribute that declares the attributes it groups, so one declaration a test carries stands for several. The framework expands a composite wherever attributes are resolved: the composed attributes run like declarations the test made itself - at their own Order - and the composite's own lifecycle behavior runs at its order too. A composite may compose another composite; a cycle is rejected when the attributes are resolved.
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public abstract class ProtoCompositeAttribute : ProtoAttribute
- Inheritance
-
ProtoCompositeAttribute
- Inherited Members
- Extension Methods
Examples
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public sealed class NorthstarMemberAttribute(string planId = PlanIds.Free) : ProtoCompositeAttribute
{
protected override IReadOnlyList<Attribute> Compose() =>
[
new NorthstarTenantAttribute(planId),
new AuthAttribute<NorthstarAuthenticator>(),
];
}
Remarks
Compose() returns the instances that run, so it must be a deterministic factory and is called once per attribute instance. Composition is by attribute instance, not by inheritance: a composite and the attributes it declares are ordinary attributes that happen to be resolved together.
Methods
Compose()
Returns the attributes this composite declares. The instances returned are the ones the framework runs; an instance that is also declared explicitly on the test runs once, and the explicit declaration wins.
protected abstract IReadOnlyList<Attribute> Compose()