Microsoft Orleans meta package to bring in the base Orleans packages for all project types.
$ dotnet add package Microsoft.Orleans.SdkMicrosoft Orleans SDK is a metapackage that includes all the necessary components to build Orleans applications. It provides both client and server functionality, making it easy to get started with Orleans without having to reference individual packages.
To use this package, install it via NuGet:
dotnet add package Microsoft.Orleans.Sdk
// Define a grain interface
public interface IHelloGrain : IGrainWithStringKey
{
Task<string> SayHello(string greeting);
}
// Implement the grain interface
public class HelloGrain : Grain, IHelloGrain
{
public Task<string> SayHello(string greeting)
{
return Task.FromResult($"Hello, {greeting}!");
}
}
using Microsoft.Extensions.Hosting;
using Orleans.Configuration;
using Orleans.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;
namespace ExampleGrains;
// Create the host
var builder = Host.CreateApplicationBuilder(args)
.UseOrleans(siloBuilder =>
{
siloBuilder
.UseLocalhostClustering();
});
// Start the host
var host = builder.Build();
await host.StartAsync();
// Get a reference to a grain and call it
var client = host.Services.GetRequiredService<IClusterClient>();
var grain = client.GetGrain<IHelloGrain>("user123");
var response = await grain.SayHello("World");
// Print the result
Console.WriteLine($"Grain response: {response}");
// Keep the host running until the application is shut down
await host.WaitForShutdownAsync();
For more comprehensive documentation, please refer to: