Class CommandExtensions
Inherited Members
Namespace: FastEndpoints
Assembly: FastEndpoints.dll
Syntax
public static class CommandExtensions
Methods
ExecuteAsync<TResult>(ICommand<TResult>, CancellationToken)
executes the command and returns a result
Declaration
public static Task<TResult> ExecuteAsync<TResult>(this ICommand<TResult> command, CancellationToken ct = default)
Parameters
Type | Name | Description |
---|---|---|
ICommand<TResult> | command | the command to execute |
CancellationToken | ct | optional cancellation token |
Returns
Type | Description |
---|---|
Task<TResult> |
Type Parameters
Name | Description |
---|---|
TResult | the type of the returned result |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | thrown when a handler for the command cannot be instantiated |
ExecuteAsync<TCommand>(TCommand, CancellationToken)
executes the command that does not return a result
Declaration
public static Task ExecuteAsync<TCommand>(this TCommand command, CancellationToken ct = default) where TCommand : ICommand
Parameters
Type | Name | Description |
---|---|---|
TCommand | command | the command to execute |
CancellationToken | ct | optional cancellation token |
Returns
Type | Description |
---|---|
Task |
Type Parameters
Name | Description |
---|---|
TCommand |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | thrown when a handler for the command cannot be instantiated |
RegisterForTesting<TCommand>(ICommandHandler<TCommand>)
registers a fake command handler for unit testing purposes
Declaration
public static void RegisterForTesting<TCommand>(this ICommandHandler<TCommand> handler) where TCommand : ICommand
Parameters
Type | Name | Description |
---|---|---|
ICommandHandler<TCommand> | handler | a fake handler instance |
Type Parameters
Name | Description |
---|---|
TCommand | type of the command |
RegisterForTesting<TCommand, TResult>(ICommandHandler<TCommand, TResult>)
registers a fake command handler for unit testing purposes
Declaration
public static void RegisterForTesting<TCommand, TResult>(this ICommandHandler<TCommand, TResult> handler) where TCommand : ICommand<TResult>
Parameters
Type | Name | Description |
---|---|---|
ICommandHandler<TCommand, TResult> | handler | a fake handler instance |
Type Parameters
Name | Description |
---|---|
TCommand | type of the command |
TResult | type of the result being returned by the handler |
RegisterGenericCommand(IServiceProvider, Type, Type)
register a generic command handler for a generic command
Declaration
public static IServiceProvider RegisterGenericCommand(this IServiceProvider sp, Type genericCommandType, Type genericHandlerType)
Parameters
Type | Name | Description |
---|---|---|
IServiceProvider | sp | |
Type | genericCommandType | the open generic type of the command. ex: |
Type | genericHandlerType | the open generic type of the command handler. ex: |
Returns
Type | Description |
---|---|
IServiceProvider |