Collection of Microsoft Orleans libraries and files needed on the server.
$ dotnet add package Microsoft.Orleans.ServerMicrosoft Orleans Server is a metapackage that includes all the necessary components to run an Orleans silo (server). It simplifies the process of setting up an Orleans server by providing a single package reference rather than requiring you to reference multiple packages individually.
To use this package, install it via NuGet:
dotnet add package Microsoft.Orleans.Server
using Microsoft.Extensions.Hosting;
using Orleans.Configuration;
using Orleans.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;
// Define a grain interface
namespace MyGrainNamespace;
public interface IMyGrain : IGrainWithStringKey
{
Task<string> DoSomething();
}
// Implement the grain interface
public class MyGrain : Grain, IMyGrain
{
public Task<string> DoSomething()
{
return Task.FromResult("Done something!");
}
}
// 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<IMyGrain>("my-grain-id");
var result = await grain.DoSomething();
// Print the result
Console.WriteLine($"Result: {result}");
// Keep the host running until the application is shut down
await host.WaitForShutdownAsync();
For more comprehensive documentation, please refer to: