@@ -13,9 +13,6 @@ public sealed partial class HandlerDiscovery
13
13
{
14
14
private readonly IList < Type > _explicitTypes = new List < Type > ( ) ;
15
15
16
- private readonly CompositeFilter < MethodInfo > _methodIncludes = new ( ) ;
17
- private readonly CompositeFilter < MethodInfo > _methodExcludes = new ( ) ;
18
-
19
16
private readonly string [ ] _validMethods =
20
17
{
21
18
HandlerChain . Handle , HandlerChain . Handles , HandlerChain . Consume , HandlerChain . Consumes , SagaChain . Orchestrate ,
@@ -25,7 +22,6 @@ public sealed partial class HandlerDiscovery
25
22
26
23
private bool _conventionalDiscoveryDisabled ;
27
24
28
- private readonly TypeQuery _handlerQuery = new ( TypeClassification . Concretes | TypeClassification . Closed ) ;
29
25
private readonly TypeQuery _messageQuery = new ( TypeClassification . Concretes | TypeClassification . Closed ) ;
30
26
31
27
public HandlerDiscovery ( )
@@ -40,48 +36,54 @@ public HandlerDiscovery()
40
36
_messageQuery . Excludes . IsNotPublic ( ) ;
41
37
}
42
38
39
+ internal CompositeFilter < MethodInfo > MethodIncludes { get ; } = new ( ) ;
40
+
41
+ internal CompositeFilter < MethodInfo > MethodExcludes { get ; } = new ( ) ;
42
+
43
43
private void specifyHandlerMethodRules ( )
44
44
{
45
45
foreach ( var methodName in _validMethods )
46
46
{
47
- _methodIncludes . WithCondition ( $ "Method name is '{ methodName } ' (case sensitive)", m => m . Name == methodName ) ;
47
+ MethodIncludes . WithCondition ( $ "Method name is '{ methodName } ' (case sensitive)", m => m . Name == methodName ) ;
48
48
49
49
var asyncName = methodName + "Async" ;
50
- _methodIncludes . WithCondition ( $ "Method name is '{ asyncName } ' (case sensitive)", m => m . Name == asyncName ) ;
50
+ MethodIncludes . WithCondition ( $ "Method name is '{ asyncName } ' (case sensitive)", m => m . Name == asyncName ) ;
51
51
}
52
52
53
- _methodIncludes . WithCondition ( "Has attribute [WolverineHandler]" , m => m . HasAttribute < WolverineHandlerAttribute > ( ) ) ;
53
+ MethodIncludes . WithCondition ( "Has attribute [WolverineHandler]" , m => m . HasAttribute < WolverineHandlerAttribute > ( ) ) ;
54
54
55
- _methodExcludes . WithCondition ( "Method is declared by object" , method => method . DeclaringType == typeof ( object ) ) ;
56
- _methodExcludes . WithCondition ( "IDisposable.Dispose()" , method => method . Name == nameof ( IDisposable . Dispose ) ) ;
57
- _methodExcludes . WithCondition ( "IAsyncDisposable.DisposeAsync()" ,
55
+ MethodExcludes . WithCondition ( "Method is declared by object" , method => method . DeclaringType == typeof ( object ) ) ;
56
+ MethodExcludes . WithCondition ( "IDisposable.Dispose()" , method => method . Name == nameof ( IDisposable . Dispose ) ) ;
57
+ MethodExcludes . WithCondition ( "IAsyncDisposable.DisposeAsync()" ,
58
58
method => method . Name == nameof ( IAsyncDisposable . DisposeAsync ) ) ;
59
- _methodExcludes . WithCondition ( "Contains Generic Parameters" , method => method . ContainsGenericParameters ) ;
60
- _methodExcludes . WithCondition ( "Special Name" , method => method . IsSpecialName ) ;
61
- _methodExcludes . WithCondition ( "Has attribute [WolverineIgnore]" ,
59
+ MethodExcludes . WithCondition ( "Contains Generic Parameters" , method => method . ContainsGenericParameters ) ;
60
+ MethodExcludes . WithCondition ( "Special Name" , method => method . IsSpecialName ) ;
61
+ MethodExcludes . WithCondition ( "Has attribute [WolverineIgnore]" ,
62
62
method => method . HasAttribute < WolverineIgnoreAttribute > ( ) ) ;
63
63
64
64
65
65
66
- _methodExcludes . WithCondition ( "Has no arguments" , m => ! m . GetParameters ( ) . Any ( ) ) ;
66
+ MethodExcludes . WithCondition ( "Has no arguments" , m => ! m . GetParameters ( ) . Any ( ) ) ;
67
67
68
- _methodExcludes . WithCondition ( "Cannot determine a valid message type" , m => m . MessageType ( ) == null ) ;
68
+ MethodExcludes . WithCondition ( "Cannot determine a valid message type" , m => m . MessageType ( ) == null ) ;
69
69
70
- _methodExcludes . WithCondition ( "Returns a primitive type" , m => m . ReturnType != typeof ( void ) && m . ReturnType . IsPrimitive ) ;
70
+ MethodExcludes . WithCondition ( "Returns a primitive type" , m => m . ReturnType != typeof ( void ) && m . ReturnType . IsPrimitive ) ;
71
71
}
72
72
73
73
private void specifyHandlerDiscovery ( )
74
74
{
75
- _handlerQuery . Includes . WithNameSuffix ( HandlerChain . HandlerSuffix ) ;
76
- _handlerQuery . Includes . WithNameSuffix ( HandlerChain . ConsumerSuffix ) ;
77
- _handlerQuery . Includes . Implements < Saga > ( ) ;
78
- _handlerQuery . Includes . Implements < IWolverineHandler > ( ) ;
79
- _handlerQuery . Includes . WithAttribute < WolverineHandlerAttribute > ( ) ;
80
-
81
- _handlerQuery . Excludes . WithCondition ( "Is not a public type" , t => isNotPublicType ( t ) ) ;
82
- _handlerQuery . Excludes . WithAttribute < WolverineIgnoreAttribute > ( ) ;
75
+ HandlerQuery . Includes . WithNameSuffix ( HandlerChain . HandlerSuffix ) ;
76
+ HandlerQuery . Includes . WithNameSuffix ( HandlerChain . ConsumerSuffix ) ;
77
+ HandlerQuery . Includes . Implements < Saga > ( ) ;
78
+ HandlerQuery . Includes . Implements < IWolverineHandler > ( ) ;
79
+ HandlerQuery . Includes . WithAttribute < WolverineHandlerAttribute > ( ) ;
80
+
81
+ HandlerQuery . Excludes . WithCondition ( "Is not a public type" , t => isNotPublicType ( t ) ) ;
82
+ HandlerQuery . Excludes . WithAttribute < WolverineIgnoreAttribute > ( ) ;
83
83
}
84
84
85
+ internal TypeQuery HandlerQuery { get ; } = new ( TypeClassification . Concretes | TypeClassification . Closed ) ;
86
+
85
87
private static bool isNotPublicType ( Type type )
86
88
{
87
89
if ( type . IsPublic ) return false ;
@@ -106,7 +108,7 @@ public HandlerDiscovery CustomizeHandlerDiscovery(Action<TypeQuery> configure)
106
108
throw new ArgumentNullException ( nameof ( configure ) ) ;
107
109
}
108
110
109
- configure ( _handlerQuery ) ;
111
+ configure ( HandlerQuery ) ;
110
112
return this ;
111
113
}
112
114
@@ -156,7 +158,7 @@ internal IEnumerable<Type> findAllMessages(HandlerGraph handlers)
156
158
Assemblies . Fill ( options . ApplicationAssembly ) ;
157
159
}
158
160
159
- return _handlerQuery . Find ( Assemblies )
161
+ return HandlerQuery . Find ( Assemblies )
160
162
. Concat ( _explicitTypes )
161
163
. Distinct ( )
162
164
. SelectMany ( actionsFromType ) . ToArray ( ) ;
@@ -166,7 +168,7 @@ internal IEnumerable<Type> findAllMessages(HandlerGraph handlers)
166
168
{
167
169
return type . GetMethods ( BindingFlags . Instance | BindingFlags . Public | BindingFlags . Static )
168
170
. Where ( x => x . DeclaringType != typeof ( object ) ) . ToArray ( )
169
- . Where ( m => _methodIncludes . Matches ( m ) && ! _methodExcludes . Matches ( m ) )
171
+ . Where ( m => MethodIncludes . Matches ( m ) && ! MethodExcludes . Matches ( m ) )
170
172
. Select ( m => ( type , m ) ) ;
171
173
}
172
174
0 commit comments