Skip to content

Commit 8a64d00

Browse files
Update Blazor SSR fortunes benchmark to use MapRazorComponents<App> (#1855)
* Update BlazorSSR to use MapRazorComponents * Update App.razor * Update BlazorSSR to include idiomatic & direct approaches
1 parent 45ac2c2 commit 8a64d00

File tree

6 files changed

+27
-13
lines changed

6 files changed

+27
-13
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" />
4+
</Found>
5+
<NotFound>
6+
not found
7+
</NotFound>
8+
</Router>

src/BenchmarksApps/TechEmpower/BlazorSSR/Components/Fortunes.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@inject Db Db
1+
@page "/fortunes"
2+
@inject Db Db
23
<!DOCTYPE html>
34
<html>
45
<head>

src/BenchmarksApps/TechEmpower/BlazorSSR/Components/FortunesEf.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@using Microsoft.EntityFrameworkCore;
1+
@page "/fortunes-ef"
2+
@using Microsoft.EntityFrameworkCore;
23
@inject Db Db
34
@inject AppDbContext DbContext
45
<!DOCTYPE html>

src/BenchmarksApps/TechEmpower/BlazorSSR/Program.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,20 @@
2525
builder.Services.AddRazorComponents();
2626
builder.Services.AddSingleton(serviceProvider =>
2727
{
28+
// TODO: This custom configured HtmlEncoder won't actually be used until Blazor supports it: https://github.com/dotnet/aspnetcore/issues/47477
2829
var settings = new TextEncoderSettings(UnicodeRanges.BasicLatin, UnicodeRanges.Katakana, UnicodeRanges.Hiragana);
2930
settings.AllowCharacter('\u2014'); // allow EM DASH through
3031
return HtmlEncoder.Create(settings);
3132
});
3233

3334
var app = builder.Build();
3435

35-
app.MapGet("/fortunes", () => new RazorComponentResult<Fortunes>());
36-
app.MapGet("/fortunes-ef", () => new RazorComponentResult<FortunesEf>());
36+
app.MapRazorComponents<App>();
37+
38+
app.MapGet("/direct/fortunes", () => new RazorComponentResult<Fortunes>());
39+
app.MapGet("/direct/fortunes-ef", () => new RazorComponentResult<FortunesEf>());
3740

3841
app.Lifetime.ApplicationStarted.Register(() => Console.WriteLine("Application started. Press Ctrl+C to shut down."));
3942
app.Lifetime.ApplicationStopping.Register(() => Console.WriteLine("Application is shutting down..."));
4043

4144
app.Run();
42-
43-
// TODO: Use this custom configured HtmlEncoder when Blazor supports it: https://github.com/dotnet/aspnetcore/issues/47477
44-
//static HtmlEncoder CreateHtmlEncoder()
45-
//{
46-
// var settings = new TextEncoderSettings(UnicodeRanges.BasicLatin, UnicodeRanges.Katakana, UnicodeRanges.Hiragana);
47-
// settings.AllowCharacter('\u2014'); // allow EM DASH through
48-
// return HtmlEncoder.Create(settings);
49-
//}

src/BenchmarksApps/TechEmpower/BlazorSSR/Properties/launchSettings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"http": {
55
"commandName": "Project",
66
"launchBrowser": true,
7+
"launchUrl": "fortunes",
78
"environmentVariables": {
89
"ASPNETCORE_ENVIRONMENT": "Development"
910
},
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
@using BlazorSSR.Database
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 Microsoft.AspNetCore.Components.Web.Virtualization
7+
@using Microsoft.JSInterop
8+
@using BlazorSSR
9+
@using BlazorSSR.Database
210
@using BlazorSSR.Models

0 commit comments

Comments
 (0)