@@ -20,16 +20,20 @@ public static class ServiceCollectionExtensions
20
20
/// </summary>
21
21
/// <typeparam name="TRequest">Request type.</typeparam>
22
22
/// <param name="services">Service container.</param>
23
+ /// <param name="configAction">Pipeline behaviors config.</param>
23
24
/// <exception cref="InvalidOperationException">When number of implementation
24
25
/// <typeparamref name="TRequest"/> and response are different.</exception>
25
- public static IServiceCollection AddPipelineBehaviorsForRequest < TRequest > ( this IServiceCollection services )
26
+ public static IServiceCollection AddPipelineBehaviorsForRequest < TRequest > ( this IServiceCollection services , Action < PipelineBehaviorsConfig > configAction = null )
26
27
{
28
+ var config = new PipelineBehaviorsConfig ( ) ;
29
+ configAction ? . Invoke ( config ) ;
30
+
27
31
Type requestType = typeof ( TRequest ) ;
28
32
Type pipeLineType = typeof ( IPipelineBehavior < , > ) ;
29
33
string requestInterfaceName = typeof ( IRequest < > ) . Name ;
30
34
31
- IList < Type > requests = GetTypes ( requestType ) ;
32
- IEnumerable < Type > pipelineBehaviors = GetPipelineBehaviors ( requestType , pipeLineType ) ;
35
+ IList < Type > requests = GetTypes ( requestType , config . RequestsAssembly ) ;
36
+ IEnumerable < Type > pipelineBehaviors = GetPipelineBehaviors ( requestType , pipeLineType , config . PipelineBehaviorsAssembly ) ;
33
37
34
38
foreach ( Type behavior in pipelineBehaviors )
35
39
{
@@ -59,14 +63,15 @@ public static IServiceCollection AddPipelineBehaviorsForRequest<TRequest>(this I
59
63
return services ;
60
64
}
61
65
62
- private static IEnumerable < Type > GetPipelineBehaviors ( Type requestType , Type pipeLineType )
63
- => Assembly . GetAssembly ( requestType ) . GetTypes ( )
66
+ private static IEnumerable < Type > GetPipelineBehaviors ( Type requestType , Type pipeLineType , Assembly behavioursAssembly )
67
+ => ( behavioursAssembly ?? Assembly . GetAssembly ( requestType ) )
68
+ . GetTypes ( )
64
69
. Where ( t
65
70
=> t . GetInterface ( pipeLineType . Name ) != null
66
71
&& t . GetGenericArguments ( ) [ 0 ] . GetInterface ( requestType . Name ) != null ) ;
67
72
68
- private static IList < Type > GetTypes ( Type type )
69
- => Assembly . GetAssembly ( type )
73
+ private static IList < Type > GetTypes ( Type type , Assembly assembly )
74
+ => ( assembly ?? Assembly . GetAssembly ( type ) )
70
75
. GetTypes ( )
71
76
. Where ( t => ! t . IsInterface && ! t . IsAbstract & type . IsAssignableFrom ( t ) )
72
77
. ToList ( ) ;
0 commit comments