@@ -8,23 +8,22 @@ namespace Hermes.Flows
8
8
{
9
9
public abstract class ProtocolFlowProvider : IProtocolFlowProvider
10
10
{
11
- protected readonly IDictionary < ProtocolFlowType , IProtocolFlow > flows ;
12
11
protected readonly ITopicEvaluator topicEvaluator ;
13
12
protected readonly IRepositoryProvider repositoryProvider ;
14
13
protected readonly ProtocolConfiguration configuration ;
15
14
15
+ IDictionary < ProtocolFlowType , IProtocolFlow > flows ;
16
+
16
17
protected ProtocolFlowProvider ( ITopicEvaluator topicEvaluator ,
17
18
IRepositoryProvider repositoryProvider ,
18
19
ProtocolConfiguration configuration )
19
20
{
20
21
this . topicEvaluator = topicEvaluator ;
21
22
this . repositoryProvider = repositoryProvider ;
22
23
this . configuration = configuration ;
23
-
24
- this . flows = this . GetFlows ( ) ;
25
24
}
26
25
27
- protected abstract IDictionary < ProtocolFlowType , IProtocolFlow > GetFlows ( ) ;
26
+ protected abstract IDictionary < ProtocolFlowType , IProtocolFlow > InitializeFlows ( ) ;
28
27
29
28
protected abstract bool IsValidPacketType ( PacketType packetType ) ;
30
29
@@ -40,7 +39,7 @@ public IProtocolFlow GetFlow (PacketType packetType)
40
39
var flow = default ( IProtocolFlow ) ;
41
40
var flowType = packetType . ToFlowType ( ) ;
42
41
43
- if ( ! this . flows . TryGetValue ( flowType , out flow ) ) {
42
+ if ( ! this . GetFlows ( ) . TryGetValue ( flowType , out flow ) ) {
44
43
var error = string . Format ( Resources . ProtocolFlowProvider_UnknownPacketType , packetType ) ;
45
44
46
45
throw new ProtocolException ( error ) ;
@@ -51,13 +50,22 @@ public IProtocolFlow GetFlow (PacketType packetType)
51
50
52
51
public T GetFlow < T > ( ) where T : class
53
52
{
54
- var pair = this . flows . FirstOrDefault ( f => f . Value is T ) ;
53
+ var pair = this . GetFlows ( ) . FirstOrDefault ( f => f . Value is T ) ;
55
54
56
55
if ( pair . Equals ( default ( KeyValuePair < ProtocolFlowType , IProtocolFlow > ) ) ) {
57
56
return default ( T ) ;
58
57
}
59
58
60
59
return pair . Value as T ;
61
60
}
61
+
62
+ private IDictionary < ProtocolFlowType , IProtocolFlow > GetFlows ( )
63
+ {
64
+ if ( this . flows == default ( IDictionary < ProtocolFlowType , IProtocolFlow > ) ) {
65
+ this . flows = this . InitializeFlows ( ) ;
66
+ }
67
+
68
+ return this . flows ;
69
+ }
62
70
}
63
71
}
0 commit comments