Skip to content

Commit fa6fb9c

Browse files
committed
Fix ci errors and build errors and add Blazor web apps sample
1 parent a6f0938 commit fa6fb9c

File tree

20 files changed

+455
-5
lines changed

20 files changed

+455
-5
lines changed

.github/workflows/build-and-deploy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040

4141
- name: Publish NuGet Package
4242
if: (github.event_name == 'release')
43-
run: dotnet nuget push 'artifacts/**/*.nupkg' -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate
43+
run: dotnet nuget push 'src/**/*.nupkg' -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate
4444

4545
# Generate the website
4646
- name: Publish Sample Page
@@ -51,5 +51,5 @@ jobs:
5151
uses: peaceiris/actions-gh-pages@v3
5252
with:
5353
github_token: ${{ secrets.GITHUB_TOKEN }}
54-
publish_dir: ./artifacts/publish/Memento.Sample.BlazorWasm/release_net8.0/wwwroot
54+
publish_dir: ./samples/Memento.Sample.BlazorWasm/bin/Release/net8.0/publish/wwwroot
5555
force_orphan: true

Memento.sln

+15-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_root", "_root", "{E9CA5D2D
1212
.editorconfig = .editorconfig
1313
.gitignore = .gitignore
1414
.github\workflows\build-and-deploy.yml = .github\workflows\build-and-deploy.yml
15-
Directory.Build.props = Directory.Build.props
15+
src\Directory.Build.props = src\Directory.Build.props
1616
docfx.json = docfx.json
1717
README.md = README.md
1818
toc.yml = toc.yml
@@ -53,6 +53,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Memento.Sample.BlazorWasm",
5353
EndProject
5454
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Memento.Sample.ConsoleApp", "samples\Memento.Sample.ConsoleApp\Memento.Sample.ConsoleApp.csproj", "{A089BC00-80C4-4074-8127-C414F2B79585}"
5555
EndProject
56+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Memento.Samples.Blazor.WebApp", "samples\Memento.Samples.Blazor.WebApp\Memento.Samples.Blazor.WebApp\Memento.Samples.Blazor.WebApp.csproj", "{AC47BE86-40AF-47CF-BC23-8D0707AF8EA4}"
57+
EndProject
58+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Memento.Samples.Blazor.WebApp.Client", "samples\Memento.Samples.Blazor.WebApp\Memento.Samples.Blazor.WebApp.Client\Memento.Samples.Blazor.WebApp.Client.csproj", "{D4B0BC5F-E0AA-403C-9DDE-777D742FC13A}"
59+
EndProject
5660
Global
5761
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5862
Debug|Any CPU = Debug|Any CPU
@@ -99,6 +103,14 @@ Global
99103
{A089BC00-80C4-4074-8127-C414F2B79585}.Debug|Any CPU.Build.0 = Debug|Any CPU
100104
{A089BC00-80C4-4074-8127-C414F2B79585}.Release|Any CPU.ActiveCfg = Release|Any CPU
101105
{A089BC00-80C4-4074-8127-C414F2B79585}.Release|Any CPU.Build.0 = Release|Any CPU
106+
{AC47BE86-40AF-47CF-BC23-8D0707AF8EA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
107+
{AC47BE86-40AF-47CF-BC23-8D0707AF8EA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
108+
{AC47BE86-40AF-47CF-BC23-8D0707AF8EA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
109+
{AC47BE86-40AF-47CF-BC23-8D0707AF8EA4}.Release|Any CPU.Build.0 = Release|Any CPU
110+
{D4B0BC5F-E0AA-403C-9DDE-777D742FC13A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
111+
{D4B0BC5F-E0AA-403C-9DDE-777D742FC13A}.Debug|Any CPU.Build.0 = Debug|Any CPU
112+
{D4B0BC5F-E0AA-403C-9DDE-777D742FC13A}.Release|Any CPU.ActiveCfg = Release|Any CPU
113+
{D4B0BC5F-E0AA-403C-9DDE-777D742FC13A}.Release|Any CPU.Build.0 = Release|Any CPU
102114
EndGlobalSection
103115
GlobalSection(SolutionProperties) = preSolution
104116
HideSolutionNode = FALSE
@@ -116,6 +128,8 @@ Global
116128
{4481A230-D66C-486F-B06A-29DECB3940FA} = {AD16691B-0034-4F49-8F90-0932C029DA3C}
117129
{8DA8C555-F65E-4419-8732-7CAD00507166} = {AD16691B-0034-4F49-8F90-0932C029DA3C}
118130
{A089BC00-80C4-4074-8127-C414F2B79585} = {AD16691B-0034-4F49-8F90-0932C029DA3C}
131+
{AC47BE86-40AF-47CF-BC23-8D0707AF8EA4} = {AD16691B-0034-4F49-8F90-0932C029DA3C}
132+
{D4B0BC5F-E0AA-403C-9DDE-777D742FC13A} = {AD16691B-0034-4F49-8F90-0932C029DA3C}
119133
EndGlobalSection
120134
GlobalSection(ExtensibilityGlobals) = postSolution
121135
SolutionGuid = {52122159-362B-41B0-BE89-5FC9BF19BE01}

samples/Memento.Sample.Blazor/Components/Counter.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<h1 class="">Async Counter Component</h1>
99
<h2>Current count: @AsyncCounterStore.State.Count</h2>
1010
<p>Loading: @AsyncCounterStore.State.IsLoading</p>
11-
11+
<p>IsBrowser: @OperatingSystem.IsBrowser()</p>
1212
<div>
1313
<button class="mt-3 btn btn-primary" @onclick="IncrementCount">Count up</button>
1414
<button class="mt-3 btn btn-primary" @onclick="CountUpMany">Count up 100 times</button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@page "/index2"
2+
3+
<PageTitle>Index2</PageTitle>
4+
@System.OperatingSystem.IsBrowser()
5+
<h1>Hello, world 22222222!</h1>
6+
7+
Welcome to your new app.
8+
9+
10+
<button @onclick="IncrementCount">Click me: @count</button>
11+
12+
@code {
13+
private int count = 0;
14+
15+
private void IncrementCount()
16+
{
17+
count++;
18+
}
19+
20+
private void DecrementCount()
21+
{
22+
count--;
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using Memento.Core;
2+
using Microsoft.JSInterop;
3+
4+
namespace Memento.Sample.Blazor;
5+
6+
/// <summary>
7+
/// Middleware for logging state changes.
8+
/// </summary>
9+
public sealed class LoggerMiddleware : Middleware {
10+
/// <summary>
11+
/// Creates a new instance of the LoggerMiddlewareHandler.
12+
/// </summary>
13+
/// <param name="provider">The service provider used to resolve required services.</param>
14+
/// <returns>A new LoggerMiddlewareHandler instance.</returns>
15+
protected override MiddlewareHandler Create(IServiceProvider provider) {
16+
return new LoggerMiddlewareHandler(
17+
provider.GetRequiredService<IJSRuntime>()
18+
);
19+
}
20+
21+
/// <summary>
22+
/// Handler for logging state changes in the LoggerMiddleware.
23+
/// </summary>
24+
/// <remarks>
25+
/// Creates a new instance of the LoggerMiddlewareHandler.
26+
/// </remarks>
27+
/// <param name="jSRuntime">The JavaScript runtime to be used for logging.</param>
28+
public class LoggerMiddlewareHandler(IJSRuntime jSRuntime) : MiddlewareHandler {
29+
private readonly IJSRuntime _jSRuntime = jSRuntime;
30+
31+
/// <summary>
32+
/// Handles logging the state changes before passing them to the next middleware.
33+
/// </summary>
34+
/// <param name="state">The current state of the application.</param>
35+
/// <param name="e">The state change event arguments.</param>
36+
/// <param name="next">The next middleware in the pipeline.</param>
37+
/// <returns>The updated state after processing by the middleware pipeline.</returns>
38+
public override RootState? HandleProviderDispatch(
39+
RootState? state,
40+
IStateChangedEventArgs<object, object> e,
41+
NextProviderMiddlewareCallback next
42+
) {
43+
_ = HandleLog(state, e);
44+
return next(state, e);
45+
}
46+
47+
/// <summary>
48+
/// Logs the state changes using the JavaScript console.
49+
/// </summary>
50+
/// <param name="state">The current state of the application.</param>
51+
/// <param name="e">The state change event arguments.</param>
52+
/// <returns>A task representing the logging operation.</returns>
53+
public async Task HandleLog(object? state, IStateChangedEventArgs<object, object> e) {
54+
if (state is null) {
55+
return;
56+
}
57+
58+
await _jSRuntime.InvokeVoidAsync("console.log", new {
59+
StateName = state.GetType().Name,
60+
State = state,
61+
EventArgs = e,
62+
});
63+
}
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
8+
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.2" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\..\..\src\Memento.Blazor\Memento.Blazor.csproj" />
17+
<ProjectReference Include="..\..\..\src\Memento.Core\Memento.Core.csproj" />
18+
<ProjectReference Include="..\..\..\src\Memento.ReduxDevTool.Browser\Memento.ReduxDevTool.Browser.csproj" />
19+
<ProjectReference Include="..\..\Memento.Sample.Blazor\Memento.Sample.Blazor.csproj" />
20+
</ItemGroup>
21+
22+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Memento.Blazor;
2+
using Memento.ReduxDevTool.Browser;
3+
using Memento.Sample.Blazor;
4+
using Memento.Sample.Blazor.Todos;
5+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
6+
7+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
8+
builder.Services
9+
.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) })
10+
.AddScoped<ITodoService, MockTodoService>()
11+
// Memento
12+
.AddMemento()
13+
.AddMiddleware(() => new LoggerMiddleware())
14+
.AddBrowserReduxDevToolMiddleware(new() {
15+
StackTraceEnabled = true,
16+
OpenDevTool = true,
17+
})
18+
.ScanAssemblyAndAddStores(typeof(Memento.Sample.Blazor.App).Assembly);
19+
await builder.Build().RunAsync();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@using Memento.Sample.Blazor.Shared
2+
3+
<Memento.Blazor.MementoInitializer />
4+
5+
<Router AppAssembly="typeof(Program).Assembly" AdditionalAssemblies="[typeof(Sample.Blazor.App).Assembly]">
6+
<Found Context="routeData">
7+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
8+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
9+
</Found>
10+
<NotFound>
11+
<PageTitle>Not found</PageTitle>
12+
<LayoutView Layout="@typeof(MainLayout)">
13+
<p role="alert">Sorry, there's nothing at this address.</p>
14+
</LayoutView>
15+
</NotFound>
16+
</Router>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@using System.Net.Http
2+
@using System.Net.Http.Json
3+
@using Microsoft.AspNetCore.Components.Forms
4+
@using Microsoft.AspNetCore.Components.Routing
5+
@using Microsoft.AspNetCore.Components.Web
6+
@using static Microsoft.AspNetCore.Components.Web.RenderMode
7+
@using Microsoft.AspNetCore.Components.Web.Virtualization
8+
@using Microsoft.JSInterop
9+
@using Memento.Samples.Blazor.WebApp.Client
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<base href="/" />
8+
<link rel="stylesheet" href="app.css" />
9+
<link rel="stylesheet" href="Memento.Samples.Blazor.WebApp.styles.css" />
10+
11+
<HeadOutlet />
12+
</head>
13+
14+
<body>
15+
<Routes @rendermode="InteractiveAuto" />
16+
<script src="_framework/blazor.web.js"></script>
17+
</body>
18+
19+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@page "/Error"
2+
@using System.Diagnostics
3+
4+
<PageTitle>Error</PageTitle>
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<p>
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
25+
</p>
26+
27+
@code{
28+
[CascadingParameter]
29+
private HttpContext? HttpContext { get; set; }
30+
31+
private string? RequestId { get; set; }
32+
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
33+
34+
protected override void OnInitialized() =>
35+
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@using System.Net.Http
2+
@using System.Net.Http.Json
3+
@using Microsoft.AspNetCore.Components.Forms
4+
@using Microsoft.AspNetCore.Components.Routing
5+
@using Microsoft.AspNetCore.Components.Web
6+
@using static Microsoft.AspNetCore.Components.Web.RenderMode
7+
@using Microsoft.AspNetCore.Components.Web.Virtualization
8+
@using Microsoft.JSInterop
9+
@using Memento.Samples.Blazor.WebApp
10+
@using Memento.Samples.Blazor.WebApp.Client
11+
@using Memento.Samples.Blazor.WebApp.Components
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\Memento.Samples.Blazor.WebApp.Client\Memento.Samples.Blazor.WebApp.Client.csproj" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.2" />
12+
</ItemGroup>
13+
14+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Memento.Blazor;
2+
using Memento.ReduxDevTool.Browser;
3+
using Memento.Sample.Blazor;
4+
using Memento.Sample.Blazor.Todos;
5+
using Memento.Samples.Blazor.WebApp.Components;
6+
7+
var builder = WebApplication.CreateBuilder(args);
8+
9+
builder.Services
10+
.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7288/") })
11+
.AddScoped<ITodoService, MockTodoService>()
12+
// Memento
13+
.AddMemento()
14+
.AddMiddleware(() => new ServerLoggerMiddleware())
15+
.AddBrowserReduxDevToolMiddleware(new() {
16+
StackTraceEnabled = true,
17+
OpenDevTool = true,
18+
}, true)
19+
.ScanAssemblyAndAddStores(typeof(Memento.Sample.Blazor._Imports).Assembly);
20+
21+
// Add services to the container.
22+
builder.Services.AddRazorComponents()
23+
.AddInteractiveServerComponents()
24+
.AddInteractiveWebAssemblyComponents();
25+
26+
var app = builder.Build();
27+
28+
// Configure the HTTP request pipeline.
29+
if (app.Environment.IsDevelopment()) {
30+
app.UseWebAssemblyDebugging();
31+
}
32+
else {
33+
app.UseExceptionHandler("/Error", createScopeForErrors: true);
34+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
35+
app.UseHsts();
36+
}
37+
38+
app.UseHttpsRedirection();
39+
40+
app.UseStaticFiles();
41+
app.UseAntiforgery();
42+
43+
app.MapRazorComponents<Memento.Samples.Blazor.WebApp.Components.App>()
44+
.AddInteractiveServerRenderMode()
45+
.AddInteractiveWebAssemblyRenderMode()
46+
.AddAdditionalAssemblies(typeof(Memento.Sample.Blazor.App).Assembly) // shared project
47+
.AddAdditionalAssemblies(typeof(Memento.Samples.Blazor.WebApp.Client._Imports).Assembly); // client project
48+
49+
app.Run();

0 commit comments

Comments
 (0)