Class CommandExtensions
Inherited Members
Namespace: FastEndpoints
Assembly: FastEndpoints.dll
Syntax
public static class CommandExtensions
Methods
AddCommandMiddleware(IServiceCollection, Action<CommandMiddlewareConfig>)
register a common middleware pipeline for command handlers. the middleware can be created as open generic classes that implement the ICommandMiddleware<TCommand, TResult> interface as well as closed generic classes implementing the same interface.
Declaration
public static IServiceCollection AddCommandMiddleware(this IServiceCollection services, Action<CommandMiddlewareConfig> config)
Parameters
Type | Name | Description |
---|---|---|
IServiceCollection | services | |
Action<CommandMiddlewareConfig> | config | configuration action for adding middleware components to the pipeline |
Returns
Type | Description |
---|---|
IServiceCollection |
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 : class, 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, Void>)
registers a fake command handler for unit testing purposes
Declaration
public static void RegisterForTesting<TCommand>(this ICommandHandler<TCommand, Void> handler) where TCommand : ICommand
Parameters
Type | Name | Description |
---|---|---|
ICommandHandler<TCommand, Void> | 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 |
RegisterGenericCommand<TCommand, THandler>(IServiceProvider)
register a generic command handler for a generic command
Declaration
public static IServiceProvider RegisterGenericCommand<TCommand, THandler>(this IServiceProvider sp) where TCommand : ICommand where THandler : ICommandHandler
Parameters
Type | Name | Description |
---|---|---|
IServiceProvider | sp |
Returns
Type | Description |
---|---|
IServiceProvider |
Type Parameters
Name | Description |
---|---|
TCommand | the type of the command |
THandler | the type of the command handler |