Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to .net 9 & added Aspire project #167

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<Project>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<PropertyGroup>
<Copyright>Copyright © 2015-2024 Petabridge</Copyright>
<Authors>Petabridge</Authors>
Expand All @@ -12,7 +18,4 @@
</PackageLicenseUrl>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>
<PropertyGroup>
<NetVersion>net8.0</NetVersion>
</PropertyGroup>
</Project>
27 changes: 20 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,33 @@
<PackageVersion Include="Akka.Persistence.Sql.Hosting" Version="1.5.30" />
<PackageVersion Include="Akka.Streams" Version="1.5.31" />
<PackageVersion Include="Akka.Streams.TestKit" Version="1.5.20" />
<PackageVersion Include="Grpc.Tools" Version="2.67.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
<PackageVersion Include="MudBlazor" Version="6.20.0" />
<PackageVersion Include="Grpc.Tools" Version="2.68.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageVersion Include="MudBlazor" Version="7.15.0" />
<PackageVersion Include="Petabridge.Cmd.Cluster" Version="1.4.3" />
<PackageVersion Include="Petabridge.Cmd.Cluster.Sharding" Version="1.4.3" />
</ItemGroup>
<!-- ASP.NET Package Versions -->
<ItemGroup>
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.11" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageVersion Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.UI" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.4" />
</ItemGroup>
<!-- Aspire Package Versions -->
<ItemGroup>
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.0.0" />
<PackageVersion Include="Aspire.Hosting.SqlServer" Version="9.0.0" />
</ItemGroup>
<!-- FluentEmail Package Versions -->
<ItemGroup>
<PackageVersion Include="FluentEmail.Mailgun" Version="3.0.2" />
Expand Down
31 changes: 31 additions & 0 deletions DrawTogether.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{DC3392A7
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawTogether.Tests", "tests\DrawTogether.Tests\DrawTogether.Tests.csproj", "{108B25F0-A606-47C6-9151-CB0095110DDC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "aspire", "aspire", "{0C6E23C7-5F35-475D-85EF-3A3FE13D814A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawTogether.AppHost", "src\DrawTogether.AppHost\DrawTogether.AppHost.csproj", "{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawTogether.MigrationService", "src\DrawTogether.MigrationService\DrawTogether.MigrationService.csproj", "{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -97,6 +103,30 @@ Global
{108B25F0-A606-47C6-9151-CB0095110DDC}.Release|x64.Build.0 = Release|Any CPU
{108B25F0-A606-47C6-9151-CB0095110DDC}.Release|x86.ActiveCfg = Release|Any CPU
{108B25F0-A606-47C6-9151-CB0095110DDC}.Release|x86.Build.0 = Release|Any CPU
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Debug|x64.ActiveCfg = Debug|Any CPU
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Debug|x64.Build.0 = Debug|Any CPU
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Debug|x86.ActiveCfg = Debug|Any CPU
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Debug|x86.Build.0 = Debug|Any CPU
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Release|Any CPU.Build.0 = Release|Any CPU
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Release|x64.ActiveCfg = Release|Any CPU
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Release|x64.Build.0 = Release|Any CPU
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Release|x86.ActiveCfg = Release|Any CPU
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF}.Release|x86.Build.0 = Release|Any CPU
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Debug|x64.ActiveCfg = Debug|Any CPU
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Debug|x64.Build.0 = Debug|Any CPU
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Debug|x86.ActiveCfg = Debug|Any CPU
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Debug|x86.Build.0 = Debug|Any CPU
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Release|Any CPU.Build.0 = Release|Any CPU
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Release|x64.ActiveCfg = Release|Any CPU
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Release|x64.Build.0 = Release|Any CPU
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Release|x86.ActiveCfg = Release|Any CPU
{2C615B52-0412-4FE2-B22C-5B1F7839F0AF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -106,5 +136,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{108B25F0-A606-47C6-9151-CB0095110DDC} = {DC3392A7-58A4-4C8C-9401-6DDCD41FBF16}
{FB2F6129-90DA-4C6C-A318-D492DE6B3DCF} = {0C6E23C7-5F35-475D-85EF-3A3FE13D814A}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"rollForward": "latestMinor",
"version": "8.0.101"
"version": "9.0.100"
}
}
6 changes: 0 additions & 6 deletions src/DrawTogether.Actors/DrawTogether.Actors.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka.Cluster.Hosting" />
<PackageReference Include="Akka.Streams" />
Expand Down
20 changes: 20 additions & 0 deletions src/DrawTogether.AppHost/DrawTogether.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<IsAspireHost>true</IsAspireHost>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
<PackageReference Include="Aspire.Hosting.SqlServer" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DrawTogether.MigrationService\DrawTogether.MigrationService.csproj" />
<ProjectReference Include="..\DrawTogether\DrawTogether.csproj" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions src/DrawTogether.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var builder = DistributedApplication.CreateBuilder(args);

var sqlServer = builder.AddSqlServer("sql");

var db = sqlServer.AddDatabase("DrawTogetherDb");

var migrationService = builder.AddProject<Projects.DrawTogether_MigrationService>("MigrationService")
.WaitFor(db)
.WithReference(db);

builder.AddProject<Projects.DrawTogether>("DrawTogether")
.WithReference(db, "DefaultConnection")
.WaitForCompletion(migrationService);

builder
.Build()
.Run();
29 changes: 29 additions & 0 deletions src/DrawTogether.AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17142;http://localhost:15099",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21049",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22281"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15099",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19227",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20048"
}
}
}
}
8 changes: 8 additions & 0 deletions src/DrawTogether.AppHost/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions src/DrawTogether.AppHost/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
6 changes: 0 additions & 6 deletions src/DrawTogether.Email/DrawTogether.Email.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentEmail.Mailgun" />
<PackageReference Include="FluentEmail.Razor" />
Expand Down
6 changes: 0 additions & 6 deletions src/DrawTogether.Entities/DrawTogether.Entities.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<ItemGroup>
<PackageReference Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" />
<PackageReference Include="Microsoft.Extensions.Hosting"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DrawTogether\DrawTogether.csproj" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions src/DrawTogether.MigrationService/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using DrawTogether.Data;
using DrawTogether.MigrationService;

var builder = Host.CreateApplicationBuilder(args);

builder.AddSqlServerDbContext<ApplicationDbContext>("DrawTogetherDb");

builder.Services.AddHostedService<Worker>();

var host = builder.Build();
host.Run();
12 changes: 12 additions & 0 deletions src/DrawTogether.MigrationService/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"DrawTogether.MigrationService": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
}
}
}
}
55 changes: 55 additions & 0 deletions src/DrawTogether.MigrationService/Worker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using DrawTogether.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;

namespace DrawTogether.MigrationService;

public class Worker(
IServiceProvider serviceProvider,
IHostApplicationLifetime hostApplicationLifetime,
ILogger<Worker> logger) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{
using var scope = serviceProvider.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();

await EnsureCreatedAsync(dbContext, stoppingToken);
await RunMigrationAsync(dbContext, stoppingToken);
}
catch (Exception ex)
{
logger.LogError(ex, "An error occurred while migrating the database");
}

hostApplicationLifetime.StopApplication();
}

private async Task EnsureCreatedAsync(ApplicationDbContext dbContext, CancellationToken cancellationToken)
{
var strategy = dbContext.Database.CreateExecutionStrategy();
var databaseCreator = dbContext.Database.GetService<IRelationalDatabaseCreator>();

await strategy.ExecuteAsync(async ct =>
{
if (!await databaseCreator.ExistsAsync(ct))
{
await databaseCreator.CreateAsync(ct);
logger.LogInformation("Database created");
}
}, cancellationToken);
}

private async Task RunMigrationAsync(ApplicationDbContext dbContext, CancellationToken cancellationToken)
{
var strategy = dbContext.Database.CreateExecutionStrategy();
await strategy.ExecuteAsync(async ct =>
{
await dbContext.Database.MigrateAsync(ct);
logger.LogInformation("Database migrated");
}, cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
8 changes: 8 additions & 0 deletions src/DrawTogether.MigrationService/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
2 changes: 1 addition & 1 deletion src/DrawTogether/Config/AkkaConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static IServiceCollection ConfigureAkka(this IServiceCollection services,

var connectionString = configuration.GetConnectionString("DefaultConnection");
if (connectionString is null)
throw new Exception("DefaultConnection setting is missing");
throw new Exception("DefaultConnection ConnectionString is missing");

var roleName = ClusterConstants.DrawStateRoleName;

Expand Down
4 changes: 1 addition & 3 deletions src/DrawTogether/DrawTogether.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-DrawTogether-519D8737-B9C5-4479-BE39-7C98C7D228C7</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<ContainerRepository>drawtogether-app</ContainerRepository>
Expand Down Expand Up @@ -32,6 +29,7 @@
<PackageReference Include="Akka.Discovery.KubernetesApi" />
<PackageReference Include="Akka.Management" />
<PackageReference Include="Akka.Persistence.Sql.Hosting" />
<PackageReference Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore"/>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
Expand Down
5 changes: 2 additions & 3 deletions src/DrawTogether/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@
})
.AddIdentityCookies();

var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
builder.AddSqlServerDbContext<ApplicationDbContext>("DefaultConnection");

builder.Services.AddDatabaseDeveloperPageExceptionFilter();

builder.Services.AddIdentityCore<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
Expand Down
Loading
Loading