-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSoftawareCqsDecoratorBuilder.cs
More file actions
38 lines (34 loc) · 1.39 KB
/
SoftawareCqsDecoratorBuilder.cs
File metadata and controls
38 lines (34 loc) · 1.39 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
namespace Microsoft.Extensions.DependencyInjection;
/// <summary>
/// Provides methods for configuring decorators for the softaware CQS infrastructure with source generation.
/// </summary>
public class SoftawareCqsDecoratorBuilder
{
internal HashSet<Type> EnabledDecorators { get; } = [];
/// <summary>
/// Adds a request handler decorator.
/// </summary>
/// <remarks>
/// The source generator reads the <c>typeof()</c> argument from the syntax tree at compile time
/// and generates explicit decorator chains for each handler.
/// At runtime, the type is recorded so that conditional registrations (inside <c>if</c> blocks)
/// can be evaluated correctly.
/// </remarks>
/// <param name="decoratorType">
/// The type of the decorator. The decorator must implement
/// <c>IRequestHandler<TRequest, TResult></c>.
/// </param>
/// <returns>The decorator builder for chaining.</returns>
public SoftawareCqsDecoratorBuilder AddRequestHandlerDecorator(Type decoratorType)
{
if (decoratorType is null)
{
throw new ArgumentNullException(nameof(decoratorType));
}
var normalizedDecoratorType = decoratorType.IsConstructedGenericType
? decoratorType.GetGenericTypeDefinition()
: decoratorType;
this.EnabledDecorators.Add(normalizedDecoratorType);
return this;
}
}