diff --git a/src/Client/Flows/ClientProtocolFlowProvider.cs b/src/Client/Flows/ClientProtocolFlowProvider.cs index 82916f24..bef5844c 100644 --- a/src/Client/Flows/ClientProtocolFlowProvider.cs +++ b/src/Client/Flows/ClientProtocolFlowProvider.cs @@ -11,7 +11,7 @@ public ClientProtocolFlowProvider (ITopicEvaluator topicEvaluator, IRepositoryPr { } - protected override IDictionary GetFlows () + protected override IDictionary InitializeFlows () { var flows = new Dictionary(); diff --git a/src/Portable/Flows/ProtocolFlowProvider.cs b/src/Portable/Flows/ProtocolFlowProvider.cs index 5c767b13..6f408eb6 100644 --- a/src/Portable/Flows/ProtocolFlowProvider.cs +++ b/src/Portable/Flows/ProtocolFlowProvider.cs @@ -8,11 +8,12 @@ namespace Hermes.Flows { public abstract class ProtocolFlowProvider : IProtocolFlowProvider { - protected readonly IDictionary flows; protected readonly ITopicEvaluator topicEvaluator; protected readonly IRepositoryProvider repositoryProvider; protected readonly ProtocolConfiguration configuration; + IDictionary flows; + protected ProtocolFlowProvider (ITopicEvaluator topicEvaluator, IRepositoryProvider repositoryProvider, ProtocolConfiguration configuration) @@ -20,11 +21,9 @@ protected ProtocolFlowProvider (ITopicEvaluator topicEvaluator, this.topicEvaluator = topicEvaluator; this.repositoryProvider = repositoryProvider; this.configuration = configuration; - - this.flows = this.GetFlows (); } - protected abstract IDictionary GetFlows (); + protected abstract IDictionary InitializeFlows (); protected abstract bool IsValidPacketType (PacketType packetType); @@ -40,7 +39,7 @@ public IProtocolFlow GetFlow (PacketType packetType) var flow = default (IProtocolFlow); var flowType = packetType.ToFlowType(); - if (!this.flows.TryGetValue (flowType, out flow)) { + if (!this.GetFlows().TryGetValue (flowType, out flow)) { var error = string.Format (Resources.ProtocolFlowProvider_UnknownPacketType, packetType); throw new ProtocolException (error); @@ -51,7 +50,7 @@ public IProtocolFlow GetFlow (PacketType packetType) public T GetFlow () where T : class { - var pair = this.flows.FirstOrDefault (f => f.Value is T); + var pair = this.GetFlows().FirstOrDefault (f => f.Value is T); if (pair.Equals (default (KeyValuePair))) { return default (T); @@ -59,5 +58,14 @@ public T GetFlow () where T : class return pair.Value as T; } + + private IDictionary GetFlows() + { + if (this.flows == default (IDictionary)) { + this.flows = this.InitializeFlows (); + } + + return this.flows; + } } } diff --git a/src/Server/Flows/ServerProtocolFlowProvider.cs b/src/Server/Flows/ServerProtocolFlowProvider.cs index 2d7bdda6..3ed1ebba 100644 --- a/src/Server/Flows/ServerProtocolFlowProvider.cs +++ b/src/Server/Flows/ServerProtocolFlowProvider.cs @@ -17,7 +17,7 @@ public ServerProtocolFlowProvider (IConnectionProvider connectionProvider, this.connectionProvider = connectionProvider; } - protected override IDictionary GetFlows () + protected override IDictionary InitializeFlows () { var flows = new Dictionary();