Skip to content
Docs Try Aspire
Docs Try

Aspire Orleans sample app

Aspire sample
C# AppHost

Clone, run, and explore this sample

This is a simple .NET app that shows how to use Orleans with Aspire orchestration.

C#Orleans
AppHost

The entry point that composes every resource and dependency in this sample's distributed application.

View on GitHub
AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var redis = builder.AddRedis("voting-redis");
var orleans = builder.AddOrleans("voting-cluster")
.WithClustering(redis)
.WithGrainStorage("votes", redis);
builder.AddProject<Projects.OrleansVoting_Service>("voting-fe")
.WithReference(orleans)
.WaitFor(redis)
.WithReplicas(3)
.WithExternalHttpEndpoints()
.WithUrlForEndpoint("https", u => u.DisplayText = "Voting App")
.WithUrlForEndpoint("http", u => u.DisplayLocation = UrlDisplayLocation.DetailsOnly)
.WithUrlForEndpoint("orleans-gateway", u => u.DisplayLocation = UrlDisplayLocation.DetailsOnly)
.WithUrlForEndpoint("orleans-silo", u => u.DisplayLocation = UrlDisplayLocation.DetailsOnly);
builder.Build().Run();
  • How to use Aspire to work with Orleans

If using the Aspire CLI, run aspire run from this directory.

If using VS Code, open this directory as a workspace and launch the OrleansVoting.AppHost project using either the Aspire or C# debuggers.

If using Visual Studio, open the solution file OrleansVoting.slnx and launch/debug the OrleansVoting.AppHost project.

If using the .NET CLI, run dotnet run from the OrleansVoting.AppHost directory.

  1. On the Resources page, click on one of the endpoints for the listed project. This launches the simple voting app.
  2. In the voting app:
    1. Enter a poll title, some questions, and click Create, or click DEMO: auto-fill poll to auto-fill the poll.
    2. On the poll page, click one of the poll options to vote for it.
    3. The results of the poll are displayed. Click the DEMO: simulate other voters button to simulate other voters voting on the poll and watch the results update.

For more information about using Orleans, see the Orleans documentation.