Created
March 22, 2019 03:55
-
-
Save ReubenBond/4c4f3c7495aca579ca5887f2ecc2c8b9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.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