Skip to content

Commit

Permalink
Merge pull request #234 from tumugin/upgrade-dotnet-9
Browse files Browse the repository at this point in the history
Upgrade dotnet 9
  • Loading branch information
tumugin authored Nov 24, 2024
2 parents 983a536 + ebc10f5 commit 7c81cae
Show file tree
Hide file tree
Showing 20 changed files with 953 additions and 914 deletions.
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "8.0.10",
"version": "9.0.0",
"commands": [
"dotnet-ef"
]
}
}
}
}
4 changes: 2 additions & 2 deletions .github/workflows/test-migration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core SDK 7.0
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
Expand All @@ -38,4 +38,4 @@ jobs:
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test migrations
run: dotnet ef database update --project Lullaby -- --environment Testing
run: dotnet ef database update --project Lullaby -- --environment Development
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core SDK 7.0
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# see: https://hub.docker.com/_/microsoft-dotnet-sdk/
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build-env

WORKDIR /App

Expand Down Expand Up @@ -30,7 +30,7 @@ RUN dotnet publish -c Release -o out

# Build runtime image
# see: https://hub.docker.com/_/microsoft-dotnet-aspnet/
FROM mcr.microsoft.com/dotnet/aspnet:8.0
FROM mcr.microsoft.com/dotnet/aspnet:9.0

WORKDIR /App/Lullaby
COPY --from=build-env /App/Lullaby/out .
Expand Down
12 changes: 6 additions & 6 deletions Lullaby.Admin/Lullaby.Admin.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand All @@ -14,14 +14,14 @@
<ItemGroup>
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.15" />
<PackageReference Include="Hangfire.Core" Version="1.8.15" />
<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.9.4-beta.1" />
<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.9.4" />
<PackageReference Include="IDisposableAnalyzers" Version="4.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.10" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="9.0.0" />
<PackageReference Include="Sentry.AspNetCore" Version="4.13.0" />
</ItemGroup>

Expand All @@ -32,7 +32,7 @@
<ItemGroup>
<Folder Include="Pages\" />
</ItemGroup>

<ItemGroup>
<Watch Include="**\*.cshtml" Exclude="node_modules\**\*;**\*.js.map;obj\**\*;bin\**\*" />
</ItemGroup>
Expand Down
16 changes: 13 additions & 3 deletions Lullaby.Admin/ServiceExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ private static void AddLullabyOidcAuthentication(this WebApplicationBuilder webA
});
}

private static bool IsTestingEnvironment(this WebApplicationBuilder webApplicationBuilder)
=> webApplicationBuilder.Environment.EnvironmentName == "Testing";

public static WebApplicationBuilder AddApplicationServices(
this WebApplicationBuilder webApplicationBuilder
)
Expand All @@ -105,9 +108,16 @@ this WebApplicationBuilder webApplicationBuilder

var dbConnectionString = webApplicationBuilder.Configuration.GetConnectionString("DefaultConnection")
?? throw new InvalidOperationException("DB ConnectionString must not be null.");
webApplicationBuilder.Services.AddDbContext<LullabyContext>(options =>
options.UseNpgsql(dbConnectionString)
);

// If it is on testing env, don't register DBContext as
// "Only a single database provider can be registered in a service provider"
// error cause since from .NET 9.0 version NpgSQL libs.
if (!webApplicationBuilder.IsTestingEnvironment())
{
webApplicationBuilder.Services.AddDbContext<LullabyContext>(options =>
options.UseNpgsql(dbConnectionString)
);
}

webApplicationBuilder.Services.AddControllersWithViews()
.AddRazorRuntimeCompilation()
Expand Down
Loading

0 comments on commit 7c81cae

Please sign in to comment.