-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterfaces.cs
More file actions
47 lines (43 loc) · 1.47 KB
/
Interfaces.cs
File metadata and controls
47 lines (43 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
namespace Odin.Patterns.CommandHandler;
/// <summary>
/// Defines a command request that doesn't return a value
/// </summary>
public interface ICommand { }
/// <summary>
/// Defines a command request that returns an operation result
/// (e.g., a new ID, a Result class, etc.)
/// or could be a query that returns query results data.
/// </summary>
/// <typeparam name="TResult"></typeparam>
public interface ICommand<out TResult> { }
/// <summary>
/// Defines the handling implementation for a command request that does not return a Result.
/// </summary>
/// <typeparam name="TCommand"></typeparam>
public interface ICommandHandler<in TCommand>
where TCommand : ICommand
{
/// <summary>
/// Handles the command request
/// </summary>
/// <param name="command"></param>
/// <param name="ct"></param>
/// <returns></returns>
Task HandleAsync(TCommand command, CancellationToken ct = default);
}
/// <summary>
/// Defines the handling implementation for a command request that returns a Result.
/// </summary>
/// <typeparam name="TCommand"></typeparam>
/// <typeparam name="TResult"></typeparam>
public interface ICommandHandler<in TCommand, TResult>
where TCommand : ICommand<TResult>
{
/// <summary>
/// Handles the command request and returns a result.
/// </summary>
/// <param name="command"></param>
/// <param name="ct"></param>
/// <returns></returns>
Task<TResult> HandleAsync(TCommand command, CancellationToken ct = default);
}