1
- using System . Reflection ;
1
+ using System . Reflection ;
2
2
using Cnblogs . Architecture . Ddd . Cqrs . Abstractions ;
3
3
using Cnblogs . Architecture . Ddd . Cqrs . DependencyInjection ;
4
4
using MediatR ;
@@ -18,6 +18,21 @@ public static class ServiceCollectionInjector
18
18
/// <param name="assemblies">命令/查询所在的程序集。</param>
19
19
/// <returns></returns>
20
20
public static CqrsInjector AddCqrs ( this IServiceCollection services , params Assembly [ ] assemblies )
21
+ {
22
+ return services . AddCqrs ( null , assemblies ) ;
23
+ }
24
+
25
+ /// <summary>
26
+ /// 添加 Cqrs 支持。
27
+ /// </summary>
28
+ /// <param name="services"><see cref="IServiceCollection" />。</param>
29
+ /// <param name="configuration">The action used to configure the MediatRServiceConfiguration.</param>
30
+ /// <param name="assemblies">命令/查询所在的程序集。</param>
31
+ /// <returns></returns>
32
+ public static CqrsInjector AddCqrs (
33
+ this IServiceCollection services ,
34
+ Action < MediatRServiceConfiguration > ? configuration ,
35
+ params Assembly [ ] assemblies )
21
36
{
22
37
services . AddTransient ( typeof ( IPipelineBehavior < , > ) , typeof ( ValidationBehavior < , > ) ) ;
23
38
services . AddTransient ( typeof ( IPipelineBehavior < , > ) , typeof ( LoggingBehavior < , > ) ) ;
@@ -27,7 +42,12 @@ public static CqrsInjector AddCqrs(this IServiceCollection services, params Asse
27
42
assemblies = [ typeof ( CqrsInjector ) . Assembly ] ;
28
43
}
29
44
30
- services . AddMediatR ( cfg => cfg . RegisterServicesFromAssemblies ( assemblies ) ) ;
45
+ services . AddMediatR ( cfg =>
46
+ {
47
+ cfg . RegisterServicesFromAssemblies ( assemblies ) ;
48
+ configuration ? . Invoke ( cfg ) ;
49
+ } ) ;
50
+
31
51
return new CqrsInjector ( services ) ;
32
52
}
33
53
}
0 commit comments