Skip to content

Class MessageBusExtensions

Namespace: Momentum.Extensions.Messaging
Assembly: Momentum.Extensions.dll

Provides extension methods for the Wolverine message bus to simplify command and query invocation.

csharp
public static class MessageBusExtensions

Inheritance

objectMessageBusExtensions

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Methods

InvokeCommandAsync<TCommandResult>(IMessageBus, ICommand<TCommandResult>, CancellationToken)

Invokes a command asynchronously through the message bus.

csharp
public static Task<TCommandResult> InvokeCommandAsync<TCommandResult>(this IMessageBus bus, ICommand<TCommandResult> command, CancellationToken cancellationToken = default)

Parameters

bus IMessageBus

The message bus instance.

command ICommand<TCommandResult>

The command to invoke.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<TCommandResult>

A task representing the asynchronous operation with the command result.

Type Parameters

TCommandResult

The type of result returned by the command.

Remarks

This method provides a strongly-typed way to invoke commands that implement

. The command will be processed by the appropriate

handler registered in the messaging system.

InvokeQueryAsync<TQueryResult>(IMessageBus, IQuery<TQueryResult>, CancellationToken)

Invokes a query asynchronously through the message bus.

csharp
public static Task<TQueryResult> InvokeQueryAsync<TQueryResult>(this IMessageBus bus, IQuery<TQueryResult> query, CancellationToken cancellationToken = default)

Parameters

bus IMessageBus

The message bus instance.

query IQuery<TQueryResult>

The query to invoke.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<TQueryResult>

A task representing the asynchronous operation with the query result.

Type Parameters

TQueryResult

The type of result returned by the query.

Remarks

This method provides a strongly-typed way to invoke queries that implement

. The query will be processed by the appropriate

handler registered in the messaging system.