Skip to content

Commit 1e51d3e

Browse files
committed
Removed Toolkit HeadElement and refactored to new .net6 template
1 parent e6ae834 commit 1e51d3e

File tree

10 files changed

+56
-93
lines changed

10 files changed

+56
-93
lines changed

LinkDotNet.Blog.IntegrationTests/Web/Pages/BlogPostPageTests.cs

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
using Microsoft.EntityFrameworkCore;
1414
using Microsoft.Extensions.DependencyInjection;
1515
using Moq;
16-
using Toolbelt.Blazor.HeadElement;
1716
using Xunit;
1817

1918
namespace LinkDotNet.Blog.IntegrationTests.Web.Pages;
@@ -86,7 +85,6 @@ private void RegisterComponents(TestContextBase ctx, ILocalStorageService localS
8685
ctx.Services.AddScoped<IRepository<BlogPost>>(_ => Repository);
8786
ctx.Services.AddScoped(_ => localStorageService ?? new Mock<ILocalStorageService>().Object);
8887
ctx.Services.AddScoped(_ => new Mock<IToastService>().Object);
89-
ctx.Services.AddScoped(_ => new Mock<IHeadElementHelper>().Object);
9088
ctx.Services.AddScoped(_ => new Mock<IUserRecordService>().Object);
9189
ctx.Services.AddScoped(_ => new AppConfiguration());
9290
}

LinkDotNet.Blog.IntegrationTests/Web/Pages/IndexTests.cs

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using LinkDotNet.Blog.Web.Shared.Services;
1111
using Microsoft.Extensions.DependencyInjection;
1212
using Moq;
13-
using Toolbelt.Blazor.HeadElement;
1413
using Xunit;
1514

1615
using Index = LinkDotNet.Blog.Web.Pages.Index;
@@ -174,7 +173,6 @@ private void RegisterComponents(TestContextBase ctx)
174173
{
175174
ctx.Services.AddScoped<IRepository<BlogPost>>(_ => Repository);
176175
ctx.Services.AddScoped(_ => CreateSampleAppConfiguration());
177-
ctx.Services.AddScoped(_ => new Mock<IHeadElementHelper>().Object);
178176
ctx.Services.AddScoped(_ => new Mock<IUserRecordService>().Object);
179177
}
180178
}

LinkDotNet.Blog.IntegrationTests/Web/Pages/SearchByTagTests.cs

-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using LinkDotNet.Blog.Web.Shared.Services;
1111
using Microsoft.Extensions.DependencyInjection;
1212
using Moq;
13-
using Toolbelt.Blazor.HeadElement;
1413
using Xunit;
1514

1615
namespace LinkDotNet.Blog.IntegrationTests.Web.Pages;
@@ -25,7 +24,6 @@ public async Task ShouldOnlyDisplayTagsGivenByParameter()
2524
await AddBlogPostWithTagAsync("Tag 1");
2625
await AddBlogPostWithTagAsync("Tag 2");
2726
ctx.Services.AddScoped<IRepository<BlogPost>>(_ => Repository);
28-
ctx.Services.AddScoped(_ => new Mock<IHeadElementHelper>().Object);
2927
ctx.Services.AddScoped(_ => new Mock<IUserRecordService>().Object);
3028
var cut = ctx.RenderComponent<SearchByTag>(p => p.Add(s => s.Tag, "Tag 1"));
3129
cut.WaitForState(() => cut.FindAll(".blog-card").Any());
@@ -41,7 +39,6 @@ public async Task ShouldHandleSpecialCharacters()
4139
using var ctx = new TestContext();
4240
await AddBlogPostWithTagAsync("C#");
4341
ctx.Services.AddScoped<IRepository<BlogPost>>(_ => Repository);
44-
ctx.Services.AddScoped(_ => new Mock<IHeadElementHelper>().Object);
4542
ctx.Services.AddScoped(_ => new Mock<IUserRecordService>().Object);
4643
var cut = ctx.RenderComponent<SearchByTag>(p => p.Add(s => s.Tag, Uri.EscapeDataString("C#")));
4744
cut.WaitForState(() => cut.FindAll(".blog-card").Any());

LinkDotNet.Blog.UnitTests/Web/Pages/AboutMeTests.cs

-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
using LinkDotNet.Blog.Web.Shared.Skills;
1515
using Microsoft.Extensions.DependencyInjection;
1616
using Moq;
17-
using Toolbelt.Blazor.HeadElement;
1817
using X.PagedList;
1918
using Xunit;
2019

@@ -101,7 +100,6 @@ private void SetupMocks(AppConfiguration config)
101100
Services.AddScoped(_ => new Mock<ISortOrderCalculator>().Object);
102101
Services.AddScoped(_ => skillRepo.Object);
103102
Services.AddScoped(_ => profileRepo.Object);
104-
Services.AddScoped(_ => new Mock<IHeadElementHelper>().Object);
105103
Services.AddScoped(_ => new Mock<IToastService>().Object);
106104
}
107105
}

LinkDotNet.Blog.Web/LinkDotNet.Blog.Web.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
<PrivateAssets>all</PrivateAssets>
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2222
</PackageReference>
23-
<PackageReference Include="Toolbelt.Blazor.HeadElement" Version="6.0.0" />
2423
</ItemGroup>
2524

2625
<ItemGroup>

LinkDotNet.Blog.Web/Pages/BlogPostPage.razor

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
@using LinkDotNet.Blog.Web.Shared.Admin
33
@using LinkDotNet.Blog.Web.Shared.Services
44
@using Markdig
5-
@using Toolbelt.Blazor.HeadElement
65
@using LinkDotNet.Blog.Domain
76
@using LinkDotNet.Blog.Infrastructure.Persistence
87
@inject IRepository<BlogPost> blogPostRepository

LinkDotNet.Blog.Web/Pages/SearchByTag.razor

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@page "/searchByTag/{tag}"
2-
@using Toolbelt.Blazor.HeadElement
32
@using LinkDotNet.Blog.Web.Shared.Services
43
@using LinkDotNet.Blog.Domain
54
@using LinkDotNet.Blog.Infrastructure.Persistence

LinkDotNet.Blog.Web/Program.cs

+56-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
using Microsoft.AspNetCore.Hosting;
1+
using Blazored.Toast;
2+
using LinkDotNet.Blog.Web.Authentication.Auth0;
3+
using LinkDotNet.Blog.Web.Authentication.Dummy;
4+
using LinkDotNet.Blog.Web.RegistrationExtensions;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.Extensions.DependencyInjection;
27
using Microsoft.Extensions.Hosting;
38

49
namespace LinkDotNet.Blog.Web;
@@ -7,10 +12,56 @@ public static class Program
712
{
813
public static void Main(string[] args)
914
{
10-
CreateHostBuilder(args).Build().Run();
15+
var builder = WebApplication.CreateBuilder(args);
16+
RegisterServices(builder);
17+
18+
var app = builder.Build();
19+
ConfigureApp(app);
20+
21+
app.Run();
22+
}
23+
24+
private static void RegisterServices(WebApplicationBuilder builder)
25+
{
26+
builder.Services.AddRazorPages();
27+
builder.Services.AddServerSideBlazor();
28+
builder.Services.AddSingleton(_ => AppConfigurationFactory.Create(builder.Configuration));
29+
builder.Services.AddBlazoredToast();
30+
builder.Services.RegisterServices();
31+
builder.Services.AddStorageProvider(builder.Configuration);
32+
33+
if (builder.Environment.IsDevelopment())
34+
{
35+
builder.Services.UseDummyAuthentication();
36+
}
37+
else
38+
{
39+
builder.Services.UseAuth0Authentication(builder.Configuration);
40+
}
1141
}
1242

13-
public static IHostBuilder CreateHostBuilder(string[] args) =>
14-
Host.CreateDefaultBuilder(args)
15-
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
43+
private static void ConfigureApp(WebApplication app)
44+
{
45+
if (app.Environment.IsDevelopment())
46+
{
47+
app.UseDeveloperExceptionPage();
48+
}
49+
else
50+
{
51+
app.UseExceptionHandler("/Error");
52+
app.UseHsts();
53+
}
54+
55+
app.UseHttpsRedirection();
56+
app.UseStaticFiles();
57+
58+
app.UseRouting();
59+
60+
app.UseCookiePolicy();
61+
app.UseAuthentication();
62+
app.UseAuthorization();
63+
64+
app.MapBlazorHub();
65+
app.MapFallbackToPage("/_Host");
66+
}
1667
}

LinkDotNet.Blog.Web/Shared/OgData.razor

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@inject NavigationManager navigationManager
2-
@using Toolbelt.Blazor.HeadElement
32

43
<HeadContent>
54
<meta name="title" property="og:title" content="@Title" />

LinkDotNet.Blog.Web/Startup.cs

-75
This file was deleted.

0 commit comments

Comments
 (0)