@@ -16,6 +16,9 @@ dotnet add package Microsoft.Orleans.Clustering.AzureStorage
1616using Microsoft .Extensions .Hosting ;
1717using Orleans .Configuration ;
1818using Orleans .Hosting ;
19+ using Microsoft .Extensions .DependencyInjection ;
20+ using System ;
21+ using System .Threading .Tasks ;
1922
2023var builder = new HostBuilder ()
2124 .UseOrleans (siloBuilder =>
@@ -34,8 +37,19 @@ var builder = new HostBuilder()
3437 });
3538 });
3639
37- // Run the host
38- await builder .RunConsoleAsync ();
40+ var host = builder .Build ();
41+ await host .StartAsync ();
42+
43+ // Get a reference to a grain and call it
44+ var client = host .Services .GetRequiredService <IClusterClient >();
45+ var grain = client .GetGrain <IHelloGrain >(" user123" );
46+ var response = await grain .SayHello (" World" );
47+
48+ // Print the result
49+ Console .WriteLine ($" Grain response: {response }" );
50+
51+ // Keep the host running until the application is shut down
52+ await host .WaitForShutdownAsync ();
3953```
4054
4155## Example - Configuring Client to Connect to Cluster
@@ -44,6 +58,9 @@ await builder.RunConsoleAsync();
4458using Microsoft .Extensions .Hosting ;
4559using Orleans ;
4660using Orleans .Configuration ;
61+ using Microsoft .Extensions .DependencyInjection ;
62+ using System ;
63+ using System .Threading .Tasks ;
4764
4865var clientBuilder = new HostBuilder ()
4966 .UseOrleansClient (clientBuilder =>
@@ -62,13 +79,24 @@ var clientBuilder = new HostBuilder()
6279 });
6380 });
6481
65- var host = await clientBuilder .StartAsync ();
82+ var host = clientBuilder .Build ();
83+ await host .StartAsync ();
6684var client = host .Services .GetRequiredService <IClusterClient >();
85+
86+ // Get a reference to a grain and call it
87+ var grain = client .GetGrain <IHelloGrain >(" user123" );
88+ var response = await grain .SayHello (" World" );
89+
90+ // Print the result
91+ Console .WriteLine ($" Grain response: {response }" );
92+
93+ // Keep the host running until the application is shut down
94+ await host .WaitForShutdownAsync ();
6795```
6896
6997## Documentation
7098For more comprehensive documentation, please refer to:
71- - [ Microsoft Orleans Documentation] ( https://docs .microsoft.com/dotnet/orleans/ )
99+ - [ Microsoft Orleans Documentation] ( https://learn .microsoft.com/dotnet/orleans/ )
72100- [ Clustering providers] ( https://learn.microsoft.com/en-us/dotnet/orleans/implementation/cluster-management )
73101- [ Azure Storage provider] ( https://learn.microsoft.com/en-us/dotnet/orleans/implementation/azure-storage-providers )
74102
0 commit comments