-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSoftawareCqsExtensions.cs
36 lines (31 loc) · 1.55 KB
/
SoftawareCqsExtensions.cs
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
using softaware.Cqs;
using softaware.Cqs.DependencyInjection;
namespace Microsoft.Extensions.DependencyInjection;
/// <summary>
/// Provides extension methods for the SimpleInjector container to configure the softaware CQS infrastructure.
/// </summary>
public static class SoftawareCqsExtensions
{
/// <summary>
/// Adds the softaware CQS infrastructure and registers all required instances in the <paramref name="services"/> collection.
/// </summary>
/// <param name="services">The service collection.</param>
/// <param name="softawareCqsTypesBuilderAction">The types builder for registering assemblies from where to find <see cref="IRequestHandler{TRequest, TResult}"/> instances.</param>
/// <returns>The softaware CQS builder.</returns>
public static SoftawareCqsBuilder AddSoftawareCqs(
this IServiceCollection services,
Action<SoftawareCqsTypesBuilder> softawareCqsTypesBuilderAction)
{
var typesBuilder = new SoftawareCqsTypesBuilder();
softawareCqsTypesBuilderAction.Invoke(typesBuilder);
services
.Scan(scan => scan
.FromAssemblies(typesBuilder.RegisteredAssemblies)
.AddClasses(classes => classes.AssignableTo(typeof(IRequestHandler<,>))
.Where(t => !t.GetDecoratorInfo().IsDecorator))
.AsImplementedInterfaces()
.WithTransientLifetime());
services.AddTransient<IRequestProcessor, DynamicRequestProcessor>();
return new SoftawareCqsBuilder(services);
}
}