-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Orleans JournaledGrain sample #7029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2023916
Orleans JournaledGrain sample
egil 34fb307
Add timestamp to projection type
egil e6397c4
Ensure projection has been materialized before returning list
egil 71bc111
Add support for navigating a todo lists history
egil 634bdfc
Allow todo lists to have different names than id's - change registry …
egil 00d5f89
Introduce constant for todo list registry id
egil efb88dc
RefreshNow is not needed when OnActivateAsync is not overridden
egil d044c5c
Update to .NET 10, Orleans 10, Aspire 13.1.0
ReubenBond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
orleans/JournaledTodoList/JournaledTodoList.AppHost/JournaledTodoList.AppHost.csproj
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Sdk Name="Aspire.AppHost.Sdk" Version="13.1.0" /> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireHost>true</IsAspireHost> | ||
| <UserSecretsId>1df8a68d-9c06-4d9a-98ed-f735876b11f7</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.AppHost" Version="13.1.0" /> | ||
| <PackageReference Include="Aspire.Hosting.Azure.Storage" Version="13.1.0" /> | ||
| <PackageReference Include="Aspire.Hosting.Orleans" Version="13.1.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\JournaledTodoList.WebApp\JournaledTodoList.WebApp.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
27 changes: 27 additions & 0 deletions
27
orleans/JournaledTodoList/JournaledTodoList.AppHost/Program.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| // Add the resources which you will use for Orleans clustering and | ||
| // grain state storage. | ||
| var sessionStorage = builder.AddAzureStorage("sessionStorage") | ||
| .RunAsEmulator(); | ||
| var persistentStorage = builder.AddAzureStorage("persistentStorage") | ||
| .RunAsEmulator(config => config.WithLifetime(ContainerLifetime.Persistent)); | ||
|
|
||
| var clusteringTable = sessionStorage.AddTables("clustering"); | ||
| var grainStorage = persistentStorage.AddBlobs("grain-state"); | ||
|
|
||
| // Add the Orleans resource to the Aspire DistributedApplication | ||
| // builder, then configure it with Azure Table Storage for clustering | ||
| // and Azure Blob Storage for grain storage. | ||
| var orleans = builder.AddOrleans("default") | ||
| .WithClustering(clusteringTable) | ||
| .WithGrainStorage("Default", grainStorage); | ||
|
|
||
| builder.AddProject<Projects.JournaledTodoList_WebApp>("webapp") | ||
| .WithReference(orleans) | ||
| .WithReplicas(3) | ||
| .WithExternalHttpEndpoints() | ||
| .WaitFor(clusteringTable) | ||
| .WaitFor(grainStorage); | ||
|
|
||
| builder.Build().Run(); |
29 changes: 29 additions & 0 deletions
29
orleans/JournaledTodoList/JournaledTodoList.AppHost/Properties/launchSettings.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17222;http://localhost:15135", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21055", | ||
| "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22157" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15135", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19238", | ||
| "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20164" | ||
| } | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
orleans/JournaledTodoList/JournaledTodoList.AppHost/appsettings.Development.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
orleans/JournaledTodoList/JournaledTodoList.AppHost/appsettings.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| } | ||
| } |
122 changes: 122 additions & 0 deletions
122
orleans/JournaledTodoList/JournaledTodoList.ServiceDefaults/Extensions.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Diagnostics.HealthChecks; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
| using Microsoft.Extensions.Logging; | ||
| using OpenTelemetry; | ||
| using OpenTelemetry.Metrics; | ||
| using OpenTelemetry.Trace; | ||
|
|
||
| namespace Microsoft.Extensions.Hosting; | ||
|
|
||
| // Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry. | ||
| // This project should be referenced by each service project in your solution. | ||
| // To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults | ||
| public static class Extensions | ||
| { | ||
| public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder | ||
| { | ||
| builder.ConfigureOpenTelemetry(); | ||
|
|
||
| builder.AddDefaultHealthChecks(); | ||
|
|
||
| builder.Services.AddServiceDiscovery(); | ||
|
|
||
| builder.Services.ConfigureHttpClientDefaults(http => | ||
| { | ||
| // Turn on resilience by default | ||
| http.AddStandardResilienceHandler(); | ||
|
|
||
| // Turn on service discovery by default | ||
| http.AddServiceDiscovery(); | ||
| }); | ||
|
|
||
| // Uncomment the following to restrict the allowed schemes for service discovery. | ||
| // builder.Services.Configure<ServiceDiscoveryOptions>(options => | ||
| // { | ||
| // options.AllowedSchemes = ["https"]; | ||
| // }); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder | ||
| { | ||
| builder.Logging.AddOpenTelemetry(logging => | ||
| { | ||
| logging.IncludeFormattedMessage = true; | ||
| logging.IncludeScopes = true; | ||
| }); | ||
|
|
||
| builder.Services.AddOpenTelemetry() | ||
| .WithMetrics(metrics => | ||
| { | ||
| metrics.AddAspNetCoreInstrumentation() | ||
| .AddHttpClientInstrumentation() | ||
| .AddRuntimeInstrumentation() | ||
| .AddMeter("Microsoft.Orleans"); | ||
| }) | ||
| .WithTracing(tracing => | ||
| { | ||
| tracing.AddSource("Microsoft.Orleans.Runtime"); | ||
| tracing.AddSource("Microsoft.Orleans.Application"); | ||
|
|
||
| tracing.AddSource(builder.Environment.ApplicationName) | ||
| .AddAspNetCoreInstrumentation() | ||
| // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) | ||
| //.AddGrpcClientInstrumentation() | ||
| .AddHttpClientInstrumentation(); | ||
| }); | ||
|
|
||
| builder.AddOpenTelemetryExporters(); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder | ||
| { | ||
| var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); | ||
|
|
||
| if (useOtlpExporter) | ||
| { | ||
| builder.Services.AddOpenTelemetry().UseOtlpExporter(); | ||
| } | ||
|
|
||
| // Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package) | ||
| //if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"])) | ||
| //{ | ||
| // builder.Services.AddOpenTelemetry() | ||
| // .UseAzureMonitor(); | ||
| //} | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder | ||
| { | ||
| builder.Services.AddHealthChecks() | ||
| // Add a default liveness check to ensure app is responsive | ||
| .AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| public static WebApplication MapDefaultEndpoints(this WebApplication app) | ||
| { | ||
| // Adding health checks endpoints to applications in non-development environments has security implications. | ||
| // See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments. | ||
| if (app.Environment.IsDevelopment()) | ||
| { | ||
| // All health checks must pass for app to be considered ready to accept traffic after starting | ||
| app.MapHealthChecks("/health"); | ||
|
|
||
| // Only health checks tagged with the "live" tag must pass for app to be considered alive | ||
| app.MapHealthChecks("/alive", new HealthCheckOptions | ||
| { | ||
| Predicate = r => r.Tags.Contains("live") | ||
| }); | ||
| } | ||
|
|
||
| return app; | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
...rnaledTodoList/JournaledTodoList.ServiceDefaults/JournaledTodoList.ServiceDefaults.csproj
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireSharedProject>true</IsAspireSharedProject> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
|
|
||
| <PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="10.2.0" /> | ||
| <PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="10.2.0" /> | ||
| <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.15.0" /> | ||
| <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.15.0" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.0" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.15.0" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.15.0" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
23 changes: 23 additions & 0 deletions
23
orleans/JournaledTodoList/JournaledTodoList.WebApp/Components/App.razor
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <base href="/" /> | ||
| <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" | ||
| integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> | ||
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css"> | ||
| <link rel="stylesheet" href="@Assets["app.css"]" /> | ||
| <link rel="stylesheet" href="@Assets["JournaledTodoList.WebApp.styles.css"]" /> | ||
| <ImportMap /> | ||
| <HeadOutlet @rendermode="InteractiveServer" /> | ||
| </head> | ||
|
|
||
| <body> | ||
| <Routes @rendermode="InteractiveServer" /> | ||
| <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" | ||
| integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script> | ||
| <script src="_framework/blazor.web.js"></script> | ||
| </body> | ||
| </html> |
24 changes: 24 additions & 0 deletions
24
orleans/JournaledTodoList/JournaledTodoList.WebApp/Components/Layout/MainLayout.razor
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| @inherits LayoutComponentBase | ||
|
|
||
| <div class="page d-flex flex-column vh-100"> | ||
| <header> | ||
| <nav class="navbar navbar-expand-lg navbar-dark bg-dark"> | ||
| <div class="container-fluid"> | ||
| <a class="navbar-brand" href="/"> | ||
| <i class="bi bi-check2-square me-2"></i> | ||
| Journaled Todo Lists | ||
| </a> | ||
| <button class="navbar-toggler" type="button" data-bs-toggle="collapse" | ||
| data-bs-target="#navbarContent" aria-controls="navbarContent" | ||
| aria-expanded="false" aria-label="Toggle navigation"> | ||
| <span class="navbar-toggler-icon"></span> | ||
| </button> | ||
| <NavBar /> | ||
| </div> | ||
| </nav> | ||
| </header> | ||
|
|
||
| <main class="container mt-4 flex-grow-1 overflow-auto"> | ||
| @Body | ||
| </main> | ||
| </div> |
20 changes: 20 additions & 0 deletions
20
orleans/JournaledTodoList/JournaledTodoList.WebApp/Components/Layout/MainLayout.razor.css
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #blazor-error-ui { | ||
| color-scheme: light only; | ||
| background: lightyellow; | ||
| bottom: 0; | ||
| box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); | ||
| box-sizing: border-box; | ||
| display: none; | ||
| left: 0; | ||
| padding: 0.6rem 1.25rem 0.7rem 1.25rem; | ||
| position: fixed; | ||
| width: 100%; | ||
| z-index: 1000; | ||
| } | ||
|
|
||
| #blazor-error-ui .dismiss { | ||
| cursor: pointer; | ||
| position: absolute; | ||
| right: 0.75rem; | ||
| top: 0.5rem; | ||
| } |
17 changes: 17 additions & 0 deletions
17
orleans/JournaledTodoList/JournaledTodoList.WebApp/Components/Layout/NavBar.razor
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <div class="collapse navbar-collapse" id="navbarContent"> | ||
| <ul class="navbar-nav"> | ||
| <li class="nav-item"> | ||
| <NavLink class="nav-link" href="" Match="NavLinkMatch.All"> | ||
| <i class="bi bi-house-door me-2"></i> Home | ||
| </NavLink> | ||
| </li> | ||
| @foreach (var list in TodoLists) | ||
| { | ||
| <li class="nav-item"> | ||
| <NavLink class="nav-link" href="@($"todolist/{list.Id}")"> | ||
| <i class="bi bi-list-task me-1"></i> @list.Name | ||
| </NavLink> | ||
| </li> | ||
| } | ||
| </ul> | ||
| </div> |
28 changes: 28 additions & 0 deletions
28
orleans/JournaledTodoList/JournaledTodoList.WebApp/Components/Layout/NavBar.razor.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| using System.Collections.Immutable; | ||
| using JournaledTodoList.WebApp.Grains; | ||
| using JournaledTodoList.WebApp.Services; | ||
|
|
||
| namespace JournaledTodoList.WebApp.Components.Layout; | ||
|
|
||
| public partial class NavBar(TodoListService todoListService) : ITodoListRegistryObserver, IDisposable | ||
| { | ||
| private IDisposable? subscription; | ||
|
|
||
| private ImmutableArray<TodoListReference> TodoLists { get; set; } = []; | ||
|
|
||
| protected override async Task OnInitializedAsync() | ||
| { | ||
| subscription = await todoListService.SubscribeAsync(this); | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| subscription?.Dispose(); | ||
| } | ||
|
|
||
| async Task ITodoListRegistryObserver.OnTodoListsChanged(ImmutableArray<TodoListReference> todoLists) => await InvokeAsync(() => | ||
| { | ||
| TodoLists = todoLists; | ||
| StateHasChanged(); | ||
| }); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both HomePage and NavBar components subscribe to the same registry observer independently, which means two separate subscriptions are created for the same data. This is inefficient and could lead to unnecessary duplicate notifications. Consider using a shared service or state management pattern to subscribe once and share the data between components, or move the subscription to a parent component that passes the data down.