Share via


MessageHandlerAttribute Class

Definition

Marks a method as a message handler for source-generated route configuration. The method signature determines the input type and optional output type.

[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)]
public sealed class MessageHandlerAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)>]
type MessageHandlerAttribute = class
    inherit Attribute
Public NotInheritable Class MessageHandlerAttribute
Inherits Attribute
Inheritance
MessageHandlerAttribute
Attributes

Examples

public partial class MyExecutor : Executor
{
    [MessageHandler]
    private async ValueTask<MyResponse> HandleQueryAsync(
        MyQuery query, IWorkflowContext ctx, CancellationToken ct)
    {
        return new MyResponse();
    }

    [MessageHandler(Yield = [typeof(StreamChunk)], Send = [typeof(InternalMessage)])]
    private void HandleStream(StreamRequest req, IWorkflowContext ctx)
    {
        // Handler with explicit yield and send types
    }
}

Remarks

Methods marked with this attribute must have a signature matching one of the following patterns:

  • void Handler(TMessage, IWorkflowContext)
  • void Handler(TMessage, IWorkflowContext, CancellationToken)
  • ValueTask Handler(TMessage, IWorkflowContext)
  • ValueTask Handler(TMessage, IWorkflowContext, CancellationToken)
  • TResult Handler(TMessage, IWorkflowContext)
  • TResult Handler(TMessage, IWorkflowContext, CancellationToken)
  • ValueTask<TResult> Handler(TMessage, IWorkflowContext)
  • ValueTask<TResult> Handler(TMessage, IWorkflowContext, CancellationToken)

The containing class must be partial and derive from Executor.

Constructors

Name Description
MessageHandlerAttribute()

Properties

Name Description
Send

Gets or sets the types that this handler may send as messages to other executors.

Yield

Gets or sets the types that this handler may yield as workflow outputs.

Applies to