Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Orleans;
using Orleans.ApplicationParts;
using Orleans.Configuration;
using Orleans.Hosting;
using Orleans.Runtime;
namespace OrleansHost
{
class Program
{
static async Task Main(string[] args)
{
// Configure the silo host
var siloHostBuilder = new SiloHostBuilder()
.Configure<ClusterOptions>(
options =>
{
options.ClusterId = hostConfig.DeploymentId;
options.ServiceId = hostConfig.DeploymentId;
})
// etc... silo config
.EnableDirectClient(); // Not needed in Orleans 2.3.0 & above
var silo = siloHostBuilder.Build();
// Start the silo
await silo.StartAsync();
var webHost = new WebHostBuilder()
.ConfigureServices(
services =>
{
// These are the important lines
services.AddSingleton(sp => silo.Services.GetRequiredService<IClusterClient>());
services.AddSingleton(sp => silo.Services.GetRequiredService<IGrainFactory>());
})
.UseStartup<WebHostStartup>()
.Build();
await webHost.StartAsync();
// TODO: support a shutdown signal.
await Task.Delay(-1, CancellationToken.None);
}
}
}
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.