Skip to content

Commit 047a6f4

Browse files
Merge pull request #3644 from rockfordlhotka/3395-tests
Bug fixes for Blazor state, rewrite BlazorExample for .NET 8
2 parents 1851319 + f4c78d8 commit 047a6f4

File tree

76 files changed

+714
-1574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+714
-1574
lines changed

Samples/BlazorExample/.dockerignore

-25
This file was deleted.
+32-32
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
4-
VisualStudioVersion = 17.0.31815.197
4+
VisualStudioVersion = 17.9.34407.89
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorExample.Server", "BlazorExample\Server\BlazorExample.Server.csproj", "{BADEFE2B-530D-463C-951F-82EF0C184B57}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorExample", "BlazorExample\BlazorExample\BlazorExample.csproj", "{F4753295-1FE8-44E6-87AF-543965CB92C5}"
77
EndProject
8-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorExample.Client", "BlazorExample\Client\BlazorExample.Client.csproj", "{42105189-2D0A-4791-B279-BD4B8E6490F7}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorExample.Client", "BlazorExample\BlazorExample.Client\BlazorExample.Client.csproj", "{2BDEAB41-F3CB-4608-8A93-52B93A47461B}"
99
EndProject
10-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorExample.Shared", "BlazorExample\Shared\BlazorExample.Shared.csproj", "{4006B525-E5D1-45EA-8A48-B12FFC738857}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BusinessLibrary", "BlazorExample\BusinessLibrary\BusinessLibrary.csproj", "{A9342BA2-11F2-4535-8CA8-032C3EEC0519}"
1111
EndProject
12-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess", "BlazorExample\DataAccess\DataAccess.csproj", "{1C0E6B48-431A-4C61-8861-21651B78313C}"
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess", "BlazorExample\DataAccess\DataAccess.csproj", "{2B70AA4C-BEFF-4F33-B6B1-EFA3FFEA6EE4}"
1313
EndProject
14-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess.EF", "BlazorExample\DataAccess.EF\DataAccess.EF.csproj", "{B662E4A0-5556-4F17-AC90-F99CE829DA78}"
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess.EF", "BlazorExample\DataAccess.EF\DataAccess.EF.csproj", "{C09ED17F-A53D-424B-8410-EF25FD89DAE0}"
1515
EndProject
16-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess.Mock", "BlazorExample\DataAccess.Mock\DataAccess.Mock.csproj", "{DB4AAED5-8EAC-45A9-BE20-F0025754D60B}"
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess.Mock", "BlazorExample\DataAccess.Mock\DataAccess.Mock.csproj", "{041EF3E4-AF97-4860-A300-A0DCFCD20682}"
1717
EndProject
1818
Global
1919
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2020
Debug|Any CPU = Debug|Any CPU
2121
Release|Any CPU = Release|Any CPU
2222
EndGlobalSection
2323
GlobalSection(ProjectConfigurationPlatforms) = postSolution
24-
{BADEFE2B-530D-463C-951F-82EF0C184B57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25-
{BADEFE2B-530D-463C-951F-82EF0C184B57}.Debug|Any CPU.Build.0 = Debug|Any CPU
26-
{BADEFE2B-530D-463C-951F-82EF0C184B57}.Release|Any CPU.ActiveCfg = Release|Any CPU
27-
{BADEFE2B-530D-463C-951F-82EF0C184B57}.Release|Any CPU.Build.0 = Release|Any CPU
28-
{42105189-2D0A-4791-B279-BD4B8E6490F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29-
{42105189-2D0A-4791-B279-BD4B8E6490F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
30-
{42105189-2D0A-4791-B279-BD4B8E6490F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
31-
{42105189-2D0A-4791-B279-BD4B8E6490F7}.Release|Any CPU.Build.0 = Release|Any CPU
32-
{4006B525-E5D1-45EA-8A48-B12FFC738857}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33-
{4006B525-E5D1-45EA-8A48-B12FFC738857}.Debug|Any CPU.Build.0 = Debug|Any CPU
34-
{4006B525-E5D1-45EA-8A48-B12FFC738857}.Release|Any CPU.ActiveCfg = Release|Any CPU
35-
{4006B525-E5D1-45EA-8A48-B12FFC738857}.Release|Any CPU.Build.0 = Release|Any CPU
36-
{1C0E6B48-431A-4C61-8861-21651B78313C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37-
{1C0E6B48-431A-4C61-8861-21651B78313C}.Debug|Any CPU.Build.0 = Debug|Any CPU
38-
{1C0E6B48-431A-4C61-8861-21651B78313C}.Release|Any CPU.ActiveCfg = Release|Any CPU
39-
{1C0E6B48-431A-4C61-8861-21651B78313C}.Release|Any CPU.Build.0 = Release|Any CPU
40-
{B662E4A0-5556-4F17-AC90-F99CE829DA78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41-
{B662E4A0-5556-4F17-AC90-F99CE829DA78}.Debug|Any CPU.Build.0 = Debug|Any CPU
42-
{B662E4A0-5556-4F17-AC90-F99CE829DA78}.Release|Any CPU.ActiveCfg = Release|Any CPU
43-
{B662E4A0-5556-4F17-AC90-F99CE829DA78}.Release|Any CPU.Build.0 = Release|Any CPU
44-
{DB4AAED5-8EAC-45A9-BE20-F0025754D60B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45-
{DB4AAED5-8EAC-45A9-BE20-F0025754D60B}.Debug|Any CPU.Build.0 = Debug|Any CPU
46-
{DB4AAED5-8EAC-45A9-BE20-F0025754D60B}.Release|Any CPU.ActiveCfg = Release|Any CPU
47-
{DB4AAED5-8EAC-45A9-BE20-F0025754D60B}.Release|Any CPU.Build.0 = Release|Any CPU
24+
{F4753295-1FE8-44E6-87AF-543965CB92C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{F4753295-1FE8-44E6-87AF-543965CB92C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{F4753295-1FE8-44E6-87AF-543965CB92C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{F4753295-1FE8-44E6-87AF-543965CB92C5}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{2BDEAB41-F3CB-4608-8A93-52B93A47461B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{2BDEAB41-F3CB-4608-8A93-52B93A47461B}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{2BDEAB41-F3CB-4608-8A93-52B93A47461B}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{2BDEAB41-F3CB-4608-8A93-52B93A47461B}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{A9342BA2-11F2-4535-8CA8-032C3EEC0519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{A9342BA2-11F2-4535-8CA8-032C3EEC0519}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{A9342BA2-11F2-4535-8CA8-032C3EEC0519}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{A9342BA2-11F2-4535-8CA8-032C3EEC0519}.Release|Any CPU.Build.0 = Release|Any CPU
36+
{2B70AA4C-BEFF-4F33-B6B1-EFA3FFEA6EE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37+
{2B70AA4C-BEFF-4F33-B6B1-EFA3FFEA6EE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
38+
{2B70AA4C-BEFF-4F33-B6B1-EFA3FFEA6EE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
39+
{2B70AA4C-BEFF-4F33-B6B1-EFA3FFEA6EE4}.Release|Any CPU.Build.0 = Release|Any CPU
40+
{C09ED17F-A53D-424B-8410-EF25FD89DAE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{C09ED17F-A53D-424B-8410-EF25FD89DAE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{C09ED17F-A53D-424B-8410-EF25FD89DAE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{C09ED17F-A53D-424B-8410-EF25FD89DAE0}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{041EF3E4-AF97-4860-A300-A0DCFCD20682}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{041EF3E4-AF97-4860-A300-A0DCFCD20682}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{041EF3E4-AF97-4860-A300-A0DCFCD20682}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{041EF3E4-AF97-4860-A300-A0DCFCD20682}.Release|Any CPU.Build.0 = Release|Any CPU
4848
EndGlobalSection
4949
GlobalSection(SolutionProperties) = preSolution
5050
HideSolutionNode = FALSE
5151
EndGlobalSection
5252
GlobalSection(ExtensibilityGlobals) = postSolution
53-
SolutionGuid = {2388C96E-E5E2-4035-A349-47B67FBA4403}
53+
SolutionGuid = {EAB52E27-B5C0-49FC-9D6D-696CE403B9FD}
5454
EndGlobalSection
5555
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
5-
<Nullable>enable</Nullable>
4+
<TargetFramework>net8.0</TargetFramework>
65
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
8+
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
79
</PropertyGroup>
810

911
<ItemGroup>
10-
<PackageReference Include="Csla.Blazor.WebAssembly" Version="7.0.0" />
11-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.5" />
12-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.5" PrivateAssets="all" />
12+
<PackageReference Include="Csla.Blazor.WebAssembly" Version="8.0.0-R24010204" />
13+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
1314
</ItemGroup>
1415

1516
<ItemGroup>
16-
<ProjectReference Include="..\Shared\BlazorExample.Shared.csproj" />
17+
<ProjectReference Include="..\BusinessLibrary\BusinessLibrary.csproj" />
1718
</ItemGroup>
1819

1920
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@page "/counter"
2+
@rendermode InteractiveAuto
3+
@implements IDisposable /* CSLA wasm pages must be IDisposable */
4+
@inject Csla.Blazor.State.StateManager StateManager
5+
6+
<PageTitle>Counter</PageTitle>
7+
8+
<h1>Counter</h1>
9+
10+
<p role="status">Current count: @currentCount</p>
11+
12+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
13+
14+
@code {
15+
private int currentCount = 0;
16+
17+
protected override async Task OnInitializedAsync()
18+
{
19+
// Every page _must_ initialize the state manager
20+
await StateManager.InitializeAsync();
21+
}
22+
23+
private void IncrementCount()
24+
{
25+
currentCount++;
26+
}
27+
28+
public void Dispose()
29+
{
30+
// wasm pages _must_ save state back to server
31+
StateManager.SaveState();
32+
}
33+
}

Samples/BlazorExample/BlazorExample/Client/Pages/EditPerson.razor renamed to Samples/BlazorExample/BlazorExample/BlazorExample.Client/Components/Pages/EditPerson.razor

+33-20
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
@page "/EditPerson"
2-
@page "/EditPerson/{id}"
3-
@using BlazorExample.Shared
4-
@using Microsoft.AspNetCore.Authorization
1+
@page "/editperson"
2+
@page "/editperson/{id}"
3+
@rendermode InteractiveWebAssembly
4+
@implements IDisposable /* CSLA wasm pages must be IDisposable */
5+
@inject Csla.Blazor.State.StateManager StateManager
56
@inject Csla.IDataPortal<PersonEdit> personEditPortal
67
@inject Csla.Blazor.ViewModel<PersonEdit> vm
78
@inject NavigationManager NavigationManager
8-
@attribute [Authorize(Roles = "Admin")]
99

1010
<h1>Edit Person</h1>
1111

@@ -15,7 +15,14 @@
1515

1616
@if (vm.Model == null)
1717
{
18-
<p>Loading Person...</p>
18+
<AuthorizeView>
19+
<Authorized>
20+
<p>Loading Person...</p>
21+
</Authorized>
22+
<NotAuthorized>
23+
<p>Not authorized</p>
24+
</NotAuthorized>
25+
</AuthorizeView>
1926
}
2027
else
2128
{
@@ -61,20 +68,26 @@ else
6168
}
6269

6370
@code {
64-
[Parameter]
65-
public string id { get; set; }
71+
[Parameter]
72+
public string? id { get; set; }
6673

67-
protected override void OnInitialized()
68-
{
69-
vm.Saved += () => NavigationManager.NavigateTo("listpersons");
70-
vm.ModelPropertyChanged += async (s, e) => await InvokeAsync(() => StateHasChanged());
71-
}
74+
protected override async Task OnInitializedAsync()
75+
{
76+
// Every page _must_ initialize the state manager
77+
await StateManager.InitializeAsync();
7278

73-
protected override async Task OnParametersSetAsync()
74-
{
75-
if (string.IsNullOrWhiteSpace(id))
76-
await vm.RefreshAsync(() => personEditPortal.CreateAsync());
77-
else
78-
await vm.RefreshAsync(() => personEditPortal.FetchAsync(int.Parse(id)));
79-
}
79+
vm.Saved += () => NavigationManager.NavigateTo("listpersons");
80+
vm.ModelPropertyChanged += async (s, e) => await InvokeAsync(() => StateHasChanged());
81+
82+
if (string.IsNullOrWhiteSpace(id))
83+
await vm.RefreshAsync(() => personEditPortal.CreateAsync());
84+
else
85+
await vm.RefreshAsync(() => personEditPortal.FetchAsync(int.Parse(id)));
86+
}
87+
88+
public void Dispose()
89+
{
90+
// wasm pages _must_ save state back to server
91+
StateManager.SaveState();
92+
}
8093
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@page "/listpersons"
2+
@attribute [StreamRendering] /* server-static pages must be streaming */
3+
@inject Csla.Blazor.State.StateManager StateManager
4+
@inject Csla.IDataPortal<PersonList> personListPortal
5+
@inject Csla.Blazor.ViewModel<PersonList> vm
6+
7+
<h1>List of People</h1>
8+
9+
<p class="alert-danger">@vm.ViewModelErrorText</p>
10+
11+
@if (vm.Model == null)
12+
{
13+
<p>Loading List...</p>
14+
}
15+
else
16+
{
17+
<p>
18+
<a href="editperson">Add person</a>
19+
</p>
20+
<table class="table">
21+
<thead>
22+
<tr>
23+
<th>Name</th>
24+
<th></th>
25+
</tr>
26+
</thead>
27+
<tbody>
28+
@foreach (var item in vm.Model)
29+
{
30+
<tr>
31+
<td>@item.Name</td>
32+
<td><a href="editperson/@item.Id">Edit</a></td>
33+
</tr>
34+
}
35+
</tbody>
36+
</table>
37+
}
38+
39+
@code {
40+
protected override async Task OnInitializedAsync()
41+
{
42+
// Every page _must_ initialize the state manager
43+
await StateManager.InitializeAsync();
44+
await vm.RefreshAsync(() => personListPortal.FetchAsync());
45+
}
46+
}

Samples/BlazorExample/BlazorExample/Client/Shared/TextInput.razor renamed to Samples/BlazorExample/BlazorExample/BlazorExample.Client/Components/Shared/TextInput.razor

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</div>
88

99
@code {
10+
#nullable disable
1011
[Parameter]
1112
public Csla.Blazor.IPropertyInfo Property { get; set; }
1213

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Csla.Configuration;
2+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
3+
4+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
5+
6+
builder.Services.AddAuthorizationCore();
7+
8+
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
9+
10+
builder.Services.AddCsla(o => o
11+
.AddBlazorWebAssembly(o => o.SyncContextWithServer = true)
12+
.Security(o => o.FlowSecurityPrincipalFromClient = true)
13+
.DataPortal(o => o.ClientSideDataPortal(o => o
14+
.UseHttpProxy(o => o.DataPortalUrl = "/api/DataPortal"))));
15+
16+
await builder.Build().RunAsync();

Samples/BlazorExample/BlazorExample/Client/_Imports.razor renamed to Samples/BlazorExample/BlazorExample/BlazorExample.Client/_Imports.razor

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
@using Microsoft.AspNetCore.Components.Forms
44
@using Microsoft.AspNetCore.Components.Routing
55
@using Microsoft.AspNetCore.Components.Web
6+
@using static Microsoft.AspNetCore.Components.Web.RenderMode
67
@using Microsoft.AspNetCore.Components.Web.Virtualization
7-
@using Microsoft.AspNetCore.Components.WebAssembly.Http
8+
@using Microsoft.AspNetCore.Components.Authorization
89
@using Microsoft.JSInterop
910
@using BlazorExample.Client
10-
@using BlazorExample.Client.Shared
11+
@using BlazorExample.Client.Components.Shared
12+
@using BusinessLibrary
13+
@using Csla
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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="..\BlazorExample.Client\BlazorExample.Client.csproj" />
11+
<ProjectReference Include="..\BusinessLibrary\BusinessLibrary.csproj" />
12+
<ProjectReference Include="..\DataAccess.EF\DataAccess.EF.csproj" />
13+
<ProjectReference Include="..\DataAccess.Mock\DataAccess.Mock.csproj" />
14+
<ProjectReference Include="..\DataAccess\DataAccess.csproj" />
15+
<PackageReference Include="Csla.AspNetCore" Version="8.0.0-R24010204" />
16+
<PackageReference Include="Csla.Blazor" Version="8.0.0-R24010204" />
17+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.0" />
18+
</ItemGroup>
19+
20+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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="bootstrap/bootstrap.min.css" />
9+
<link rel="stylesheet" href="app.css" />
10+
<link rel="stylesheet" href="BlazorExample.styles.css" />
11+
<link rel="icon" type="image/png" href="favicon.png" />
12+
<HeadOutlet />
13+
</head>
14+
15+
<body>
16+
<Routes />
17+
<script src="_framework/blazor.web.js"></script>
18+
</body>
19+
20+
</html>

0 commit comments

Comments
 (0)