Created
October 3, 2018 23:01
-
-
Save ReubenBond/81cc5df63bfb7b700289decd7a5576fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp2.1</TargetFramework> | |
<LangVersion>7.3</LangVersion> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="2.1.0"> | |
<PrivateAssets>all</PrivateAssets> | |
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | |
</PackageReference> | |
<PackageReference Include="Microsoft.Orleans.OrleansRuntime" Version="2.1.0" /> | |
</ItemGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using Microsoft.Extensions.DependencyInjection; | |
using Orleans; | |
using Orleans.Hosting; | |
namespace OrleansListDynamic | |
{ | |
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
var silo = new SiloHostBuilder() | |
.UseLocalhostClustering() | |
.EnableDirectClient() | |
.Build(); | |
await silo.StartAsync(); | |
var client = silo.Services.GetRequiredService<IClusterClient>(); | |
var grain = client.GetGrain<IMyGrain>(0); | |
var result = await grain.Echo( | |
new List<KeyValuePair<string, dynamic>> | |
{ | |
new KeyValuePair<string, dynamic>("we", 1), | |
new KeyValuePair<string, dynamic>("have", Guid.NewGuid()), | |
new KeyValuePair<string, dynamic>("liftoff", DateTime.UtcNow), | |
}); | |
Console.WriteLine($"Results ({result.Count}):"); | |
foreach (var (key, value) in result) | |
{ | |
Console.WriteLine($" * {key} = {value}"); | |
} | |
} | |
} | |
public interface IMyGrain : IGrainWithIntegerKey | |
{ | |
Task<T> Echo<T>(T value); | |
} | |
public class MyGrain : Grain, IMyGrain | |
{ | |
public Task<T> Echo<T>(T value) => Task.FromResult(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment