Skip to content

Commit 331f1a9

Browse files
jorikAaronontheweb
andauthored
Upgraded to .net 9 & added Aspire project (#167)
Co-authored-by: Aaron Stannard <[email protected]>
1 parent bf959ea commit 331f1a9

23 files changed

+250
-43
lines changed

Directory.Build.props

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<Project>
2+
<PropertyGroup>
3+
<TargetFramework>net9.0</TargetFramework>
4+
<Nullable>enable</Nullable>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
</PropertyGroup>
7+
28
<PropertyGroup>
39
<Copyright>Copyright © 2015-2024 Petabridge</Copyright>
410
<Authors>Petabridge</Authors>
@@ -12,7 +18,4 @@
1218
</PackageLicenseUrl>
1319
<NoWarn>$(NoWarn);CS1591</NoWarn>
1420
</PropertyGroup>
15-
<PropertyGroup>
16-
<NetVersion>net8.0</NetVersion>
17-
</PropertyGroup>
1821
</Project>

Directory.Packages.props

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,33 @@
1212
<PackageVersion Include="Akka.Persistence.Sql.Hosting" Version="1.5.30" />
1313
<PackageVersion Include="Akka.Streams" Version="1.5.32" />
1414
<PackageVersion Include="Akka.Streams.TestKit" Version="1.5.20" />
15-
<PackageVersion Include="Grpc.Tools" Version="2.68.1" />
16-
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
17-
<PackageVersion Include="MudBlazor" Version="6.20.0" />
15+
<PackageVersion Include="Grpc.Tools" Version="2.68.1">
16+
<PrivateAssets>all</PrivateAssets>
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
</PackageVersion>
19+
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
20+
<PackageVersion Include="MudBlazor" Version="7.15.0" />
1821
<PackageVersion Include="Petabridge.Cmd.Cluster" Version="1.4.3" />
1922
<PackageVersion Include="Petabridge.Cmd.Cluster.Sharding" Version="1.4.3" />
2023
</ItemGroup>
2124
<!-- ASP.NET Package Versions -->
2225
<ItemGroup>
23-
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.11" />
24-
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.11" />
25-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10" />
26-
<PackageVersion Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.11" />
26+
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="9.0.0" />
27+
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.0" />
28+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
29+
<PrivateAssets>all</PrivateAssets>
30+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
31+
</PackageVersion>
32+
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
33+
<PackageVersion Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
34+
<PackageVersion Include="Microsoft.AspNetCore.Identity.UI" Version="9.0.0" />
2735
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.4" />
2836
</ItemGroup>
37+
<!-- Aspire Package Versions -->
38+
<ItemGroup>
39+
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.0.0" />
40+
<PackageVersion Include="Aspire.Hosting.SqlServer" Version="9.0.0" />
41+
</ItemGroup>
2942
<!-- FluentEmail Package Versions -->
3043
<ItemGroup>
3144
<PackageVersion Include="FluentEmail.Mailgun" Version="3.0.2" />

DrawTogether.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{DC3392A7
2727
EndProject
2828
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawTogether.Tests", "tests\DrawTogether.Tests\DrawTogether.Tests.csproj", "{108B25F0-A606-47C6-9151-CB0095110DDC}"
2929
EndProject
30+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "aspire", "aspire", "{0C6E23C7-5F35-475D-85EF-3A3FE13D814A}"
31+
EndProject
32+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawTogether.AppHost", "src\DrawTogether.AppHost\DrawTogether.AppHost.csproj", "{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}"
33+
EndProject
34+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawTogether.MigrationService", "src\DrawTogether.MigrationService\DrawTogether.MigrationService.csproj", "{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}"
35+
EndProject
3036
Global
3137
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3238
Debug|Any CPU = Debug|Any CPU
@@ -97,6 +103,30 @@ Global
97103
{108B25F0-A606-47C6-9151-CB0095110DDC}.Release|x64.Build.0 = Release|Any CPU
98104
{108B25F0-A606-47C6-9151-CB0095110DDC}.Release|x86.ActiveCfg = Release|Any CPU
99105
{108B25F0-A606-47C6-9151-CB0095110DDC}.Release|x86.Build.0 = Release|Any CPU
106+
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
107+
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Debug|Any CPU.Build.0 = Debug|Any CPU
108+
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Debug|x64.ActiveCfg = Debug|Any CPU
109+
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Debug|x64.Build.0 = Debug|Any CPU
110+
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Debug|x86.ActiveCfg = Debug|Any CPU
111+
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Debug|x86.Build.0 = Debug|Any CPU
112+
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Release|Any CPU.ActiveCfg = Release|Any CPU
113+
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Release|Any CPU.Build.0 = Release|Any CPU
114+
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Release|x64.ActiveCfg = Release|Any CPU
115+
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Release|x64.Build.0 = Release|Any CPU
116+
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Release|x86.ActiveCfg = Release|Any CPU
117+
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Release|x86.Build.0 = Release|Any CPU
118+
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
119+
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
120+
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Debug|x64.ActiveCfg = Debug|Any CPU
121+
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Debug|x64.Build.0 = Debug|Any CPU
122+
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Debug|x86.ActiveCfg = Debug|Any CPU
123+
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Debug|x86.Build.0 = Debug|Any CPU
124+
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
125+
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Release|Any CPU.Build.0 = Release|Any CPU
126+
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Release|x64.ActiveCfg = Release|Any CPU
127+
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Release|x64.Build.0 = Release|Any CPU
128+
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Release|x86.ActiveCfg = Release|Any CPU
129+
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Release|x86.Build.0 = Release|Any CPU
100130
EndGlobalSection
101131
GlobalSection(SolutionProperties) = preSolution
102132
HideSolutionNode = FALSE
@@ -106,5 +136,6 @@ Global
106136
EndGlobalSection
107137
GlobalSection(NestedProjects) = preSolution
108138
{108B25F0-A606-47C6-9151-CB0095110DDC} = {DC3392A7-58A4-4C8C-9401-6DDCD41FBF16}
139+
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF} = {0C6E23C7-5F35-475D-85EF-3A3FE13D814A}
109140
EndGlobalSection
110141
EndGlobal

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
33
"rollForward": "latestMinor",
4-
"version": "8.0.101"
4+
"version": "9.0.100"
55
}
66
}

src/DrawTogether.Actors/DrawTogether.Actors.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
</PropertyGroup>
8-
93
<ItemGroup>
104
<PackageReference Include="Akka.Cluster.Hosting" />
115
<PackageReference Include="Akka.Streams" />
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />
4+
5+
<PropertyGroup>
6+
<OutputType>Exe</OutputType>
7+
<IsAspireHost>true</IsAspireHost>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Aspire.Hosting.AppHost" />
12+
<PackageReference Include="Aspire.Hosting.SqlServer" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\DrawTogether.MigrationService\DrawTogether.MigrationService.csproj" />
17+
<ProjectReference Include="..\DrawTogether\DrawTogether.csproj" />
18+
</ItemGroup>
19+
20+
</Project>

src/DrawTogether.AppHost/Program.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var builder = DistributedApplication.CreateBuilder(args);
2+
3+
var sqlServer = builder.AddSqlServer("sql");
4+
5+
var db = sqlServer.AddDatabase("DrawTogetherDb");
6+
7+
var migrationService = builder.AddProject<Projects.DrawTogether_MigrationService>("MigrationService")
8+
.WaitFor(db)
9+
.WithReference(db);
10+
11+
builder.AddProject<Projects.DrawTogether>("DrawTogether")
12+
.WithReference(db, "DefaultConnection")
13+
.WaitForCompletion(migrationService);
14+
15+
builder
16+
.Build()
17+
.Run();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"https": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "https://localhost:17142;http://localhost:15099",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21049",
13+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22281"
14+
}
15+
},
16+
"http": {
17+
"commandName": "Project",
18+
"dotnetRunMessages": true,
19+
"launchBrowser": true,
20+
"applicationUrl": "http://localhost:15099",
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development",
23+
"DOTNET_ENVIRONMENT": "Development",
24+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19227",
25+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20048"
26+
}
27+
}
28+
}
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning",
6+
"Aspire.Hosting.Dcp": "Warning"
7+
}
8+
}
9+
}

src/DrawTogether.Email/DrawTogether.Email.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
</PropertyGroup>
8-
93
<ItemGroup>
104
<PackageReference Include="FluentEmail.Mailgun" />
115
<PackageReference Include="FluentEmail.Razor" />

src/DrawTogether.Entities/DrawTogether.Entities.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
</PropertyGroup>
8-
93
<ItemGroup>
104
<PackageReference Include="Akka" />
115
</ItemGroup>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Worker">
2+
3+
<ItemGroup>
4+
<PackageReference Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" />
5+
<PackageReference Include="Microsoft.Extensions.Hosting"/>
6+
</ItemGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\DrawTogether\DrawTogether.csproj" />
10+
</ItemGroup>
11+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using DrawTogether.Data;
2+
using DrawTogether.MigrationService;
3+
4+
var builder = Host.CreateApplicationBuilder(args);
5+
6+
builder.AddSqlServerDbContext<ApplicationDbContext>("DrawTogetherDb");
7+
8+
builder.Services.AddHostedService<Worker>();
9+
10+
var host = builder.Build();
11+
host.Run();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"DrawTogether.MigrationService": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"environmentVariables": {
8+
"DOTNET_ENVIRONMENT": "Development"
9+
}
10+
}
11+
}
12+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using DrawTogether.Data;
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Infrastructure;
4+
using Microsoft.EntityFrameworkCore.Storage;
5+
6+
namespace DrawTogether.MigrationService;
7+
8+
public class Worker(
9+
IServiceProvider serviceProvider,
10+
IHostApplicationLifetime hostApplicationLifetime,
11+
ILogger<Worker> logger) : BackgroundService
12+
{
13+
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
14+
{
15+
try
16+
{
17+
using var scope = serviceProvider.CreateScope();
18+
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
19+
20+
await EnsureCreatedAsync(dbContext, stoppingToken);
21+
await RunMigrationAsync(dbContext, stoppingToken);
22+
}
23+
catch (Exception ex)
24+
{
25+
logger.LogError(ex, "An error occurred while migrating the database");
26+
}
27+
28+
hostApplicationLifetime.StopApplication();
29+
}
30+
31+
private async Task EnsureCreatedAsync(ApplicationDbContext dbContext, CancellationToken cancellationToken)
32+
{
33+
var strategy = dbContext.Database.CreateExecutionStrategy();
34+
var databaseCreator = dbContext.Database.GetService<IRelationalDatabaseCreator>();
35+
36+
await strategy.ExecuteAsync(async ct =>
37+
{
38+
if (!await databaseCreator.ExistsAsync(ct))
39+
{
40+
await databaseCreator.CreateAsync(ct);
41+
logger.LogInformation("Database created");
42+
}
43+
}, cancellationToken);
44+
}
45+
46+
private async Task RunMigrationAsync(ApplicationDbContext dbContext, CancellationToken cancellationToken)
47+
{
48+
var strategy = dbContext.Database.CreateExecutionStrategy();
49+
await strategy.ExecuteAsync(async ct =>
50+
{
51+
await dbContext.Database.MigrateAsync(ct);
52+
logger.LogInformation("Database migrated");
53+
}, cancellationToken);
54+
}
55+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.Hosting.Lifetime": "Information"
6+
}
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.Hosting.Lifetime": "Information"
6+
}
7+
}
8+
}

src/DrawTogether/Config/AkkaConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static IServiceCollection ConfigureAkka(this IServiceCollection services,
2323

2424
var connectionString = configuration.GetConnectionString("DefaultConnection");
2525
if (connectionString is null)
26-
throw new Exception("DefaultConnection setting is missing");
26+
throw new Exception("DefaultConnection ConnectionString is missing");
2727

2828
var roleName = ClusterConstants.DrawStateRoleName;
2929

src/DrawTogether/DrawTogether.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
5-
<Nullable>enable</Nullable>
6-
<ImplicitUsings>enable</ImplicitUsings>
74
<UserSecretsId>aspnet-DrawTogether-519D8737-B9C5-4479-BE39-7C98C7D228C7</UserSecretsId>
85
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
96
<ContainerRepository>drawtogether-app</ContainerRepository>
@@ -32,6 +29,7 @@
3229
<PackageReference Include="Akka.Discovery.KubernetesApi" />
3330
<PackageReference Include="Akka.Management" />
3431
<PackageReference Include="Akka.Persistence.Sql.Hosting" />
32+
<PackageReference Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" />
3533
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore"/>
3634
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore"/>
3735
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />

src/DrawTogether/Program.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@
4242
})
4343
.AddIdentityCookies();
4444

45-
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
46-
builder.Services.AddDbContext<ApplicationDbContext>(options =>
47-
options.UseSqlServer(connectionString));
45+
builder.AddSqlServerDbContext<ApplicationDbContext>("DefaultConnection");
46+
4847
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
4948

5049
builder.Services.AddIdentityCore<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)

0 commit comments

Comments
 (0)