Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit bfd3217

Browse files
committed
Fix issue on Flow Provider
1 parent 6153d57 commit bfd3217

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/Client/Flows/ClientProtocolFlowProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public ClientProtocolFlowProvider (ITopicEvaluator topicEvaluator, IRepositoryPr
1111
{
1212
}
1313

14-
protected override IDictionary<ProtocolFlowType, IProtocolFlow> GetFlows ()
14+
protected override IDictionary<ProtocolFlowType, IProtocolFlow> InitializeFlows ()
1515
{
1616
var flows = new Dictionary<ProtocolFlowType, IProtocolFlow>();
1717

src/Portable/Flows/ProtocolFlowProvider.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@ namespace Hermes.Flows
88
{
99
public abstract class ProtocolFlowProvider : IProtocolFlowProvider
1010
{
11-
protected readonly IDictionary<ProtocolFlowType, IProtocolFlow> flows;
1211
protected readonly ITopicEvaluator topicEvaluator;
1312
protected readonly IRepositoryProvider repositoryProvider;
1413
protected readonly ProtocolConfiguration configuration;
1514

15+
IDictionary<ProtocolFlowType, IProtocolFlow> flows;
16+
1617
protected ProtocolFlowProvider (ITopicEvaluator topicEvaluator,
1718
IRepositoryProvider repositoryProvider,
1819
ProtocolConfiguration configuration)
1920
{
2021
this.topicEvaluator = topicEvaluator;
2122
this.repositoryProvider = repositoryProvider;
2223
this.configuration = configuration;
23-
24-
this.flows = this.GetFlows ();
2524
}
2625

27-
protected abstract IDictionary<ProtocolFlowType, IProtocolFlow> GetFlows ();
26+
protected abstract IDictionary<ProtocolFlowType, IProtocolFlow> InitializeFlows ();
2827

2928
protected abstract bool IsValidPacketType (PacketType packetType);
3029

@@ -40,7 +39,7 @@ public IProtocolFlow GetFlow (PacketType packetType)
4039
var flow = default (IProtocolFlow);
4140
var flowType = packetType.ToFlowType();
4241

43-
if (!this.flows.TryGetValue (flowType, out flow)) {
42+
if (!this.GetFlows().TryGetValue (flowType, out flow)) {
4443
var error = string.Format (Resources.ProtocolFlowProvider_UnknownPacketType, packetType);
4544

4645
throw new ProtocolException (error);
@@ -51,13 +50,22 @@ public IProtocolFlow GetFlow (PacketType packetType)
5150

5251
public T GetFlow<T> () where T : class
5352
{
54-
var pair = this.flows.FirstOrDefault (f => f.Value is T);
53+
var pair = this.GetFlows().FirstOrDefault (f => f.Value is T);
5554

5655
if (pair.Equals (default (KeyValuePair<ProtocolFlowType, IProtocolFlow>))) {
5756
return default (T);
5857
}
5958

6059
return pair.Value as T;
6160
}
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+
}
6270
}
6371
}

src/Server/Flows/ServerProtocolFlowProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public ServerProtocolFlowProvider (IConnectionProvider connectionProvider,
1717
this.connectionProvider = connectionProvider;
1818
}
1919

20-
protected override IDictionary<ProtocolFlowType, IProtocolFlow> GetFlows ()
20+
protected override IDictionary<ProtocolFlowType, IProtocolFlow> InitializeFlows ()
2121
{
2222
var flows = new Dictionary<ProtocolFlowType, IProtocolFlow>();
2323

0 commit comments

Comments
 (0)