Skip to content

Commit 3dedbf7

Browse files
committed
Add sample on how to discover page components in WASM project
1 parent b00f79b commit 3dedbf7

File tree

15 files changed

+164
-3
lines changed

15 files changed

+164
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Samples for ASP.NET Core 6.0, 7.0 and 8.0 RC 2 (504)
1+
# Samples for ASP.NET Core 6.0, 7.0 and 8.0 RC 2 (505)
22

3-
- Samples for ASP.NET Core **8.0 RC 2** is available [here](/projects/.net8) (41).
3+
- Samples for ASP.NET Core **8.0 RC 2** is available [here](/projects/.net8) (42).
44
- Samples for ASP.NET Core **7.0** is available [here](/projects/.net7) (45).
55
- Samples for ASP.NET Core **8.0 Preview 6** using EdgeDB.NET is [here](https://github.com/edgedb/edgedb-net).
66

projects/.net8/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ASP.NET 8.0 Preview 7 (41)
1+
# ASP.NET 8.0 Preview 7 (42)
22

33
These samples require [.NET 8.0 RC 2](https://github.com/dotnet/installer#table).
44

@@ -71,6 +71,10 @@ These samples require [.NET 8.0 RC 2](https://github.com/dotnet/installer#table)
7171

7272
This sample shows how to access `HttpContext` from a static Razor component.
7373

74+
* [RazorComponentThirteen](RazorComponentThirteen)
75+
76+
This sample shows how to use `.AddAdditionalAssemblies` to allow the a host project to discover Page components in a separate WASM project.
77+
7478
## Blazor SSR Form Handling
7579

7680
* [RazorFormHandlingOne](RazorFormHandlingOne)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dotnet.defaultSolution": "RazorComponentTen.sln"
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Accessing WASM Pages in mixed environment host
2+
3+
`.AddAdditionalAssemblies` allows the host project to discover Page components in a WASM project.
4+
5+
``` csharp
6+
app.MapRazorComponents<RazorComponentThirteen.App>()
7+
.AddInteractiveWebAssemblyRenderMode()
8+
.AddAdditionalAssemblies(typeof(Wasm.Pages.Index).Assembly);
9+
`
10+
11+
The Web Assembly components **need to be hosted in a separate project**.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorComponentTen", "RazorComponentTen\RazorComponentTen.csproj", "{C2CFE3B6-2C5A-464A-BB5F-56DB73FAE3A6}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wasm", "Wasm\Wasm.csproj", "{FD20A862-F038-4B95-8EA2-2DD1CF8A267F}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{C2CFE3B6-2C5A-464A-BB5F-56DB73FAE3A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{C2CFE3B6-2C5A-464A-BB5F-56DB73FAE3A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{C2CFE3B6-2C5A-464A-BB5F-56DB73FAE3A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{C2CFE3B6-2C5A-464A-BB5F-56DB73FAE3A6}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{FD20A862-F038-4B95-8EA2-2DD1CF8A267F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{FD20A862-F038-4B95-8EA2-2DD1CF8A267F}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{FD20A862-F038-4B95-8EA2-2DD1CF8A267F}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{FD20A862-F038-4B95-8EA2-2DD1CF8A267F}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {5F05B384-C974-4F1F-BDF3-8873320A01D6}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
6+
<title>Blazor Multi Render</title>
7+
<base href="/" />
8+
<link href="https://fastly.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
9+
<HeadOutlet />
10+
</head>
11+
<body>
12+
13+
<Router AppAssembly="@typeof(App).Assembly">
14+
<Found Context="routeData">
15+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
16+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
17+
</Found>
18+
</Router>
19+
20+
<script src="_framework/blazor.web.js" suppress-error="BL9992"></script>
21+
</body>
22+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@page "/ssr"
2+
3+
This Blazor Page Component is rendered using Server-Side Rendering (SSR).
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
builder.Services.AddRazorComponents()
4+
.AddInteractiveWebAssemblyComponents();
5+
6+
builder.Services.AddAntiforgery();
7+
8+
var app = builder.Build();
9+
10+
app.UseHttpsRedirection();
11+
12+
app.UseStaticFiles();
13+
app.UseAntiforgery();
14+
app.MapRazorComponents<RazorComponentThirteen.App>()
15+
.AddInteractiveWebAssemblyRenderMode()
16+
.AddAdditionalAssemblies(typeof(Wasm.Pages.Index).Assembly);
17+
18+
app.Run();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<RazorLangVersion>8.0</RazorLangVersion>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\Wasm\Wasm.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.0-rc.2.*" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="container">
4+
@Body
5+
</div>

0 commit comments

Comments
 (0)