Skip to content

Commit

Permalink
🌈upgrade to .net 8
Browse files Browse the repository at this point in the history
Transition to .NET 8 for Improved Performance, Stability, and Feature Integration
  • Loading branch information
neozhu authored Dec 6, 2023
2 parents 85bbb35 + 8ae7225 commit 6eedc78
Show file tree
Hide file tree
Showing 38 changed files with 407 additions and 360 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# - name: Autobuild
# uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -54,7 +54,17 @@ jobs:
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Setup .NET SDK
uses: actions/[email protected]
with:
dotnet-version: '8.0.x'

- name: Restore dependencies
run: dotnet restore CleanArchitecture.Blazor.sln

- name: Build
run: dotnet build CleanArchitecture.Blazor.sln --configuration Debug --no-restore

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore CleanArchitecture.Blazor.sln
- name: Build
Expand Down
25 changes: 14 additions & 11 deletions src/Application/Application.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>CleanArchitecture.Blazor.Application</RootNamespace>
<AssemblyName>CleanArchitecture.Blazor.Application</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>default</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Ardalis.Specification" Version="7.0.0" />
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="ClosedXML" Version="0.102.1" />
<PackageReference Include="jcamp.FluentEmail.Core" Version="3.2.0" />
<PackageReference Include="Ardalis.Specification" Version="8.0.0" />
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="ClosedXML" Version="0.104.0-preview2" />
<PackageReference Include="jcamp.FluentEmail.Core" Version="3.7.0" />
<PackageReference Include="jcamp.FluentEmail.MailKit" Version="3.7.0" />
<PackageReference Include="jcamp.FluentEmail.Razor" Version="3.7.0" />
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="FluentValidation" Version="11.8.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.8.0" />
<PackageReference Include="FluentValidation" Version="11.8.1" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.8.1" />
<PackageReference Include="LazyCache" Version="2.4.0" />
<PackageReference Include="LazyCache.AspNetCore" Version="2.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.13" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.2" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.13" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0-preview3.23201.1" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="8.0.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.7" />
<PackageReference Include="Hangfire.Core" Version="1.8.6" />
</ItemGroup>
<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions src/Domain/Domain.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>CleanArchitecture.Blazor.Domain</RootNamespace>
<AssemblyName>CleanArchitecture.Blazor.Domain</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="12.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
</ItemGroup>

</Project>
34 changes: 31 additions & 3 deletions src/Infrastructure/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using ZiggyCreatures.Caching.Fusion;

namespace CleanArchitecture.Blazor.Infrastructure;

Expand All @@ -37,6 +38,7 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi

services
.AddAuthenticationService(configuration)
.AddFusionCacheService()
.AddSimpleJwtService(options =>
{
options.UseCookie = false;
Expand Down Expand Up @@ -72,7 +74,7 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi
};
});

services.AddScoped<AuthenticationStateProvider, BlazorAuthStateProvider>();

services.AddSingleton<IUsersStateContainer, UsersStateContainer>();

return services;
Expand Down Expand Up @@ -215,6 +217,8 @@ private static IServiceCollection AddAuthenticationService(this IServiceCollecti
services.Configure<IdentityOptions>(options =>
{
var identitySettings = configuration.GetRequiredSection(IdentitySettings.Key).Get<IdentitySettings>();


// Password settings
options.Password.RequireDigit = identitySettings!.RequireDigit;
options.Password.RequiredLength = identitySettings.RequiredLength;
Expand All @@ -237,7 +241,7 @@ private static IServiceCollection AddAuthenticationService(this IServiceCollecti
});

services.AddScoped<IIdentityService, IdentityService>()
.AddAuthorization(options =>
.AddAuthorizationCore(options =>
{
options.AddPolicy("CanPurge", policy => policy.RequireUserName(UserName.Administrator));
// Here I stored necessary permissions/roles in a constant
Expand All @@ -253,6 +257,7 @@ private static IServiceCollection AddAuthenticationService(this IServiceCollecti
.AddAuthentication()
.AddJwtBearer(options =>
{

options.SaveToken = true;
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new TokenValidationParameters()
Expand Down Expand Up @@ -281,7 +286,10 @@ private static IServiceCollection AddAuthenticationService(this IServiceCollecti
}
};
});

services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/pages/authentication/login";
});
services.AddSingleton<UserDataProvider>()
.AddSingleton<IUserDataProvider>(sp =>
{
Expand All @@ -293,6 +301,24 @@ private static IServiceCollection AddAuthenticationService(this IServiceCollecti
return services;
}

private static IServiceCollection AddFusionCacheService(this IServiceCollection services)
{
services.AddMemoryCache();
services.AddFusionCache().WithDefaultEntryOptions(new FusionCacheEntryOptions
{
// CACHE DURATION
Duration = TimeSpan.FromMinutes(30),
// FAIL-SAFE OPTIONS
IsFailSafeEnabled = true,
FailSafeMaxDuration = TimeSpan.FromHours(2),
FailSafeThrottleDuration = TimeSpan.FromSeconds(30),
// FACTORY TIMEOUTS
FactorySoftTimeout = TimeSpan.FromMilliseconds(100),
FactoryHardTimeout = TimeSpan.FromMilliseconds(1500)
});
return services;
}

private static IServiceCollection AddSimpleJwtService(this IServiceCollection services,
Action<SimpleJwtOptions> options)
{
Expand All @@ -312,4 +338,6 @@ private static IServiceCollection AddSimpleJwtService(this IServiceCollection se

return services;
}


}
44 changes: 22 additions & 22 deletions src/Infrastructure/Infrastructure.csproj
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>CleanArchitecture.Blazor.Infrastructure</RootNamespace>
<AssemblyName>CleanArchitecture.Blazor.Infrastructure</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>default</LangVersion>
</PropertyGroup>
<ItemGroup>

<PackageReference Include="EFCore.NamingConventions" Version="7.0.2" />
<PackageReference Include="jcamp.FluentEmail.MailKit" Version="3.2.0" />
<PackageReference Include="jcamp.FluentEmail.Razor" Version="3.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.13" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="7.0.13" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="7.0.13" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
<PackageReference Include="EFCore.NamingConventions" Version="8.0.0-rc.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.13" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="7.0.13" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
<PackageReference Include="QuestPDF" Version="2023.10.1" />
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="6.3.0" />
<PackageReference Include="Serilog.Sinks.Postgresql.Alternative" Version="3.5.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="QuestPDF" Version="2023.10.2" />
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="6.4.0" />
<PackageReference Include="Serilog.Sinks.Postgresql.Alternative" Version="4.0.2" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.Enrichers.ClientInfo" Version="2.0.3" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.SQLite" Version="6.0.0" />
<PackageReference Include="ZiggyCreatures.FusionCache" Version="0.24.0" />

</ItemGroup>
<ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions src/Infrastructure/Services/JWT/AuthStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CleanArchitecture.Blazor.Infrastructure.Services.JWT;
public class AuthStore:BaseAuthStore
{
}
33 changes: 33 additions & 0 deletions src/Infrastructure/Services/JWT/BaseAuthStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace CleanArchitecture.Blazor.Infrastructure.Services.JWT;
public abstract class BaseAuthStore
{
public string? AccessToken { get; set; }
public string? RefreshToken { get; set; }
public delegate void OnSaveEventHandler(object sender, BaseAuthStore authStore);
public event OnSaveEventHandler? OnSave;

public void Save(string accessToken, string refreshToken)
{
AccessToken = accessToken;
RefreshToken = refreshToken;
OnSave?.Invoke(this, this);
}

public void Clear()
{
AccessToken = null;
AccessToken = null;
OnSave?.Invoke(this, this);
}




}
22 changes: 0 additions & 22 deletions src/Infrastructure/Services/JWT/BlazorAuthStateProvider.cs

This file was deleted.

3 changes: 2 additions & 1 deletion src/Migrators/Migrators.MSSQL/Migrators.MSSQL.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>CleanArchitecture.Blazor.Migrators.MSSQL</AssemblyName>
<RootNamespace>CleanArchitecture.Blazor.Migrators.MSSQL</RootNamespace>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>CleanArchitecture.Blazor.Migrators.PostgreSQL</AssemblyName>
<RootNamespace>CleanArchitecture.Blazor.Migrators.PostgreSQL</RootNamespace>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/Migrators/Migrators.SqLite/Migrators.SqLite.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>CleanArchitecture.Blazor.Migrators.SqLite</AssemblyName>
<RootNamespace>CleanArchitecture.Blazor.Migrators.SqLite</RootNamespace>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 6eedc78

Please sign in to comment.