Skip to content

Commit 43660b7

Browse files
Support WebAssembly (#10)
* Factor out common parts of the WebAssembly boot logic * Set up WebAssembly sample project * Actually start the components on WebAssembly * Make a separate sample page
1 parent 357d21c commit 43660b7

File tree

21 files changed

+434
-293
lines changed

21 files changed

+434
-293
lines changed

AspNetCore.sln

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server
17581758
EndProject
17591759
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorUnitedApp", "src\Components\Samples\BlazorUnitedApp\BlazorUnitedApp.csproj", "{09962BE7-48EC-44EA-B86A-3652FF0D7D1A}"
17601760
EndProject
1761+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorUnitedApp.WebAssembly", "src\Components\Samples\BlazorUnitedApp.WebAssembly\BlazorUnitedApp.WebAssembly.csproj", "{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}"
1762+
EndProject
17611763
Global
17621764
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17631765
Debug|Any CPU = Debug|Any CPU
@@ -10551,6 +10553,22 @@ Global
1055110553
{09962BE7-48EC-44EA-B86A-3652FF0D7D1A}.Release|x64.Build.0 = Release|Any CPU
1055210554
{09962BE7-48EC-44EA-B86A-3652FF0D7D1A}.Release|x86.ActiveCfg = Release|Any CPU
1055310555
{09962BE7-48EC-44EA-B86A-3652FF0D7D1A}.Release|x86.Build.0 = Release|Any CPU
10556+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10557+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Debug|Any CPU.Build.0 = Debug|Any CPU
10558+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Debug|arm64.ActiveCfg = Debug|Any CPU
10559+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Debug|arm64.Build.0 = Debug|Any CPU
10560+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Debug|x64.ActiveCfg = Debug|Any CPU
10561+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Debug|x64.Build.0 = Debug|Any CPU
10562+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Debug|x86.ActiveCfg = Debug|Any CPU
10563+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Debug|x86.Build.0 = Debug|Any CPU
10564+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Release|Any CPU.ActiveCfg = Release|Any CPU
10565+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Release|Any CPU.Build.0 = Release|Any CPU
10566+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Release|arm64.ActiveCfg = Release|Any CPU
10567+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Release|arm64.Build.0 = Release|Any CPU
10568+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Release|x64.ActiveCfg = Release|Any CPU
10569+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Release|x64.Build.0 = Release|Any CPU
10570+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Release|x86.ActiveCfg = Release|Any CPU
10571+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D}.Release|x86.Build.0 = Release|Any CPU
1055410572
EndGlobalSection
1055510573
GlobalSection(SolutionProperties) = preSolution
1055610574
HideSolutionNode = FALSE
@@ -11419,6 +11437,7 @@ Global
1141911437
{74377D3E-E0C6-41A4-89ED-11A9C00142A9} = {166E48ED-9738-4E13-8618-0D805F6F0F65}
1142011438
{3C7C65BF-0C13-418E-90BD-EC9C3CD282CB} = {74377D3E-E0C6-41A4-89ED-11A9C00142A9}
1142111439
{09962BE7-48EC-44EA-B86A-3652FF0D7D1A} = {5FE1FBC1-8CE3-4355-9866-44FE1307C5F1}
11440+
{42DA21DE-8DC8-4BED-BCE8-D7DDA9CEC60D} = {5FE1FBC1-8CE3-4355-9866-44FE1307C5F1}
1142211441
EndGlobalSection
1142311442
GlobalSection(ExtensibilityGlobals) = postSolution
1142411443
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}

src/Components/Components.slnf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"src\\Components\\Forms\\src\\Microsoft.AspNetCore.Components.Forms.csproj",
1616
"src\\Components\\Forms\\test\\Microsoft.AspNetCore.Components.Forms.Tests.csproj",
1717
"src\\Components\\Samples\\BlazorServerApp\\BlazorServerApp.csproj",
18+
"src\\Components\\Samples\\BlazorUnitedApp.WebAssembly\\BlazorUnitedApp.WebAssembly.csproj",
1819
"src\\Components\\Samples\\BlazorUnitedApp\\BlazorUnitedApp.csproj",
1920
"src\\Components\\Server\\src\\Microsoft.AspNetCore.Components.Server.csproj",
2021
"src\\Components\\Server\\test\\Microsoft.AspNetCore.Components.Server.Tests.csproj",
@@ -142,4 +143,4 @@
142143
"src\\WebEncoders\\src\\Microsoft.Extensions.WebEncoders.csproj"
143144
]
144145
}
145-
}
146+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
5+
<IsShippingPackage>false</IsShippingPackage>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly" />
11+
<Reference Include="System.Net.Http.Json" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
5+
using System.Net.Http;
6+
7+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
8+
9+
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
10+
11+
await builder.Build().RunAsync();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@using System.Net.Http
2+
@using System.Net.Http.Json
3+
@using Microsoft.AspNetCore.Components.Routing
4+
@using Microsoft.AspNetCore.Components.Web
5+
@using Microsoft.AspNetCore.Components.WebAssembly.Http
6+
@using Microsoft.JSInterop
7+
@using BlazorUnitedApp.WebAssembly

src/Components/Samples/BlazorUnitedApp/BlazorUnitedApp.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
@@ -9,9 +9,14 @@
99
<ItemGroup>
1010
<Reference Include="Microsoft.AspNetCore" />
1111
<Reference Include="Microsoft.AspNetCore.Components.Server" />
12+
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" />
1213
<Reference Include="Microsoft.AspNetCore.HttpsPolicy" />
1314
<Reference Include="Microsoft.AspNetCore.Mvc" />
1415
<Reference Include="Microsoft.Extensions.Hosting" />
1516
</ItemGroup>
1617

18+
<ItemGroup>
19+
<ProjectReference Include="..\BlazorUnitedApp.WebAssembly\BlazorUnitedApp.WebAssembly.csproj" />
20+
</ItemGroup>
21+
1722
</Project>

src/Components/Samples/BlazorUnitedApp/Pages/CounterServer.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
<PageTitle>Counter</PageTitle>
44

5-
<h1>Counter</h1>
5+
<h1>Counter (interactive on server)</h1>
66

77
<CounterUI InitialCount="100" rendermode="@WebComponentRenderMode.Server" />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@page "/counter-webassembly"
2+
3+
<PageTitle>Counter</PageTitle>
4+
5+
<h1>Counter (interactive on WebAssembly)</h1>
6+
7+
<CounterUI InitialCount="100" rendermode="@WebComponentRenderMode.WebAssembly" />

src/Components/Samples/BlazorUnitedApp/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using System.Globalization;
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
24
using BlazorUnitedApp.Data;
3-
using BlazorUnitedApp.Pages;
4-
using Microsoft.AspNetCore.Mvc;
5-
using Microsoft.AspNetCore.Mvc.RazorPages;
65

76
var builder = WebApplication.CreateBuilder(args);
87

@@ -22,6 +21,7 @@
2221

2322
app.UseHttpsRedirection();
2423

24+
app.UseBlazorFrameworkFiles(); // Enable WebAssembly
2525
app.UseStaticFiles();
2626

2727
app.UseRouting();

0 commit comments

Comments
 (0)