TaskHub.Shared

Pipeline Attributes

The command pipeline uses attributes to control the registration and execution order of behaviors.

[Order] Attribute

The OrderAttribute is used to define the priority of a behavior.

Usage

[Order(100)]
public class MyBehavior : IPreBehavior<MyCommand, MyResult> { ... }

Impact on Execution

Default Value: If the attribute is missing, the system defaults to int.MinValue, meaning it will likely run before behaviors that have an explicit order defined (unless they use a value lower than int.MinValue).


[SharedBehavior] Attribute

The SharedBehaviorAttribute is a marker attribute used during assembly scanning.

Usage

[SharedBehavior]
public class ValidationBehavior<TCommand, TResult> : IPreBehavior<TCommand, TResult> { ... }

Purpose

It indicates that the behavior is generic and should be applied to all commands that match its generic constraints. This is particularly useful for cross-cutting concerns like validation, logging, or transaction management that apply to many different command types.


[Span] Attribute

While not directly used for behavior ordering, the SpanAttribute (found in TaskHub.Shared.Commands.Abstractions.Attributes) is used to provide metadata for telemetry.

Usage

[Span("user.create")]
public class CreateUserHandler : ICommandHandler<CreateUserCommand, Result> { ... }

Purpose

It allows customizing the name of the OpenTelemetry span created for the handler. If not provided, the system defaults to the class name.