Skip to content

Commit

Permalink
Adds IOrleansFunctionProvider so that only one function needs to be…
Browse files Browse the repository at this point in the history
… modified when adding a new Orleans example.
  • Loading branch information
Kritner committed Oct 26, 2018
1 parent aeb788d commit c826103
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
19 changes: 10 additions & 9 deletions src/Kritner.OrleansGettingStarted.Client/OrleansExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ namespace Kritner.OrleansGettingStarted.Client
public class OrleansExamples
{
private const string ESCAPE_STRING = "-1";
private readonly IOrleansFunctionProvider _orleansFunctionProvider;

private readonly List<IOrleansFunction> _orleansFunctions = new List<IOrleansFunction>()
public OrleansExamples(IOrleansFunctionProvider orleansFunctionProvider)
{
new HelloWorld(),
new MultipleInstantiations(),
new StatefulWork()
};

_orleansFunctionProvider = orleansFunctionProvider;
}

public async Task ChooseFunction(IClusterClient clusterClient)
{
var orleansFunctions = _orleansFunctionProvider.GetOrleansFunctions();

var input = string.Empty;
while (input != ESCAPE_STRING)
{
Console.WriteLine("Pick a function to use for Orleans demonstration:");
ConsoleHelpers.LineSeparator();
for (int i = 0; i < _orleansFunctions.Count; i++)
for (int i = 0; i < orleansFunctions.Count; i++)
{
Console.WriteLine($" {i} - {_orleansFunctions[i].Description}");
Console.WriteLine($" {i} - {orleansFunctions[i].Description}");
}

Console.WriteLine("-1 - to exit");
Expand All @@ -49,7 +50,7 @@ public async Task ChooseFunction(IClusterClient clusterClient)

try
{
await _orleansFunctions[inputResult].PerformFunction(clusterClient);
await orleansFunctions[inputResult].PerformFunction(clusterClient);
ConsoleHelpers.LineSeparator();
}
catch(ArgumentOutOfRangeException)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Kritner.OrleansGettingStarted.Client.OrleansFunctionExamples
{
public interface IOrleansFunctionProvider
{
IList<IOrleansFunction> GetOrleansFunctions();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Kritner.OrleansGettingStarted.Client.OrleansFunctionExamples
{
public class OrleansFunctionProvider : IOrleansFunctionProvider
{
public IList<IOrleansFunction> GetOrleansFunctions()
{
return new List<IOrleansFunction>()
{
new HelloWorld(),
new MultipleInstantiations(),
new StatefulWork()
};
}
}
}
6 changes: 4 additions & 2 deletions src/Kritner.OrleansGettingStarted.Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Kritner.OrleansGettingStarted.GrainInterfaces;
using Kritner.OrleansGettingStarted.Client.OrleansFunctionExamples;
using Kritner.OrleansGettingStarted.GrainInterfaces;
using Microsoft.Extensions.Logging;
using Orleans;
using Orleans.Configuration;
Expand All @@ -24,7 +25,8 @@ private static async Task<int> RunMainAsync()
{
using (var client = await StartClientWithRetries())
{
await new OrleansExamples().ChooseFunction(client);
await new OrleansExamples(new OrleansFunctionProvider())
.ChooseFunction(client);
}

return 0;
Expand Down

0 comments on commit c826103

Please sign in to comment.