Repository navigation
Expand file tree
/
Copy pathCommandExtensions.cs
More file actions
82 lines (73 loc) · 2.21 KB
/
Copy pathCommandExtensions.cs
File metadata and controls
82 lines (73 loc) · 2.21 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
namespace ManagedCode.Communication.Commands;
/// <summary>
/// Extension methods for Command classes to provide fluent API
/// </summary>
public static class CommandExtensions
{
/// <summary>
/// Sets the correlation ID for the command
/// </summary>
public static T WithCorrelationId<T>(this T command, string correlationId) where T : ICommand
{
command.CorrelationId = correlationId;
return command;
}
/// <summary>
/// Sets the causation ID for the command
/// </summary>
public static T WithCausationId<T>(this T command, string causationId) where T : ICommand
{
command.CausationId = causationId;
return command;
}
/// <summary>
/// Sets the trace ID for the command
/// </summary>
public static T WithTraceId<T>(this T command, string traceId) where T : ICommand
{
command.TraceId = traceId;
return command;
}
/// <summary>
/// Sets the span ID for the command
/// </summary>
public static T WithSpanId<T>(this T command, string spanId) where T : ICommand
{
command.SpanId = spanId;
return command;
}
/// <summary>
/// Sets the user ID for the command
/// </summary>
public static T WithUserId<T>(this T command, string userId) where T : ICommand
{
command.UserId = userId;
return command;
}
/// <summary>
/// Sets the session ID for the command
/// </summary>
public static T WithSessionId<T>(this T command, string sessionId) where T : ICommand
{
command.SessionId = sessionId;
return command;
}
/// <summary>
/// Sets metadata for the command using a configuration action
/// </summary>
public static T WithMetadata<T>(this T command, Action<CommandMetadata> configureMetadata) where T : ICommand
{
command.Metadata ??= new CommandMetadata();
configureMetadata(command.Metadata);
return command;
}
/// <summary>
/// Sets metadata for the command
/// </summary>
public static T WithMetadata<T>(this T command, CommandMetadata metadata) where T : ICommand
{
command.Metadata = metadata;
return command;
}
}