Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<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>
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
You can’t perform that action at this time.