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

Upgrade api to dotnet 8 and associated dependencies #873

Merged
merged 3 commits into from
Jan 27, 2024
Merged
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
4 changes: 2 additions & 2 deletions ClemBot.Api/ClemBot.Api.Common/ClemBot.Api.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup>

Expand Down
17 changes: 8 additions & 9 deletions ClemBot.Api/ClemBot.Api.Core/ClemBot.Api.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<UserSecretsId>95286ed9-8628-45df-b16a-e46644da6b69</UserSecretsId>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup>

Expand All @@ -16,17 +16,16 @@
<PackageReference Include="FluentValidation.AspNetCore" Version="11.2.2" />
<PackageReference Include="LazyCache" Version="2.4.0" />
<PackageReference Include="LazyCache.AspNetCore" Version="2.4.0" />
<PackageReference Include="linq2db" Version="4.3.0" />
<PackageReference Include="linq2db.EntityFrameworkCore" Version="7.0.0-rc.9473" />
<PackageReference Include="MediatR" Version="11.0.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="linq2db" Version="5.3.2" />
<PackageReference Include="linq2db.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.0" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.0" NoWarn="NU1605" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.0" />
<PackageReference Include="NodaTime" Version="3.1.5" />
<PackageReference Include="NodaTime" Version="3.1.10" />
<PackageReference Include="NodaTime.Serialization.SystemTextJson" Version="1.0.0" />
<PackageReference Include="Npgsql.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Npgsql.NodaTime" Version="7.0.0" />
<PackageReference Include="Npgsql.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Npgsql.NodaTime" Version="8.0.1" />
<PackageReference Include="Quartz" Version="3.5.0" />
<PackageReference Include="Quartz.AspNetCore" Version="3.5.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
Expand Down
12 changes: 8 additions & 4 deletions ClemBot.Api/ClemBot.Api.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,14 @@
builder.Services.AddScoped<IDiscordAuthManager, DiscordAuthManager>();

// Configure Mediatr and the pipelines
builder.Services.AddMediatR(typeof(Program), typeof(GuildSandboxAuthorizeService));
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(GuildSandboxAuthorizeBehavior<,>));
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(CacheRequestBehavior<,>));
builder.Services.AddMediatR(config =>
{
config.RegisterServicesFromAssemblyContaining<Program>();
config.RegisterServicesFromAssemblyContaining<GuildSandboxAuthorizeService>();
config.AddOpenBehavior(typeof(LoggingBehavior<,>));
config.AddOpenBehavior(typeof(GuildSandboxAuthorizeBehavior<,>));
config.AddOpenBehavior(typeof(CacheRequestBehavior<,>));
});

// Specify Swagger startup options
builder.Services.AddSwaggerGen(o => {
Expand Down
16 changes: 8 additions & 8 deletions ClemBot.Api/ClemBot.Api.Data/ClemBot.Api.Data.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<UserSecretsId>9f2f92d0-9337-40e6-94dc-d7874e885acf</UserSecretsId>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
<LangVersion>11</LangVersion>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="7.0.0" />
<PackageReference Include="Npgsql.NodaTime" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="8.0.0" />
<PackageReference Include="Npgsql.NodaTime" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace ClemBot.Api.Services.Caching.Channels;

public class ChannelCacheHandlers :
RequestHandler<ClearChannelRequest>,
IRequestHandler<ClearChannelRequest>,
IRequestHandler<ChannelExistsRequest, bool>
{
private readonly IAppCache _cache;
Expand All @@ -28,8 +28,11 @@ public async Task<bool> Handle(ChannelExistsRequest request, CancellationToken c
() => _context.Channels.AnyAsync(x => x.Id == request.Id),
TimeSpan.FromHours(6));

protected override void Handle(ClearChannelRequest request)
=> _cache.Remove(GetCacheKey(request.Id));
public Task Handle(ClearChannelRequest request, CancellationToken cancellationToken)
{
_cache.Remove(GetCacheKey(request.Id));
return Task.CompletedTask;
}

private static string GetCacheKey(ulong id)
=> $"{nameof(ChannelExistsRequest)}:{id}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public CommandCacheHandler(IAppCache cache, ClemBotContext context)
_context = context;
}

public Task<Unit> Handle(ClearCommandRestrictionRequest request, CancellationToken cancellationToken)
public Task Handle(ClearCommandRestrictionRequest request, CancellationToken cancellationToken)
{
_cache.Remove(GetCacheKey(request.Id, request.CommandName));
return Unit.Task;
return Task.CompletedTask;
}

public async Task<List<CommandRestriction>> Handle(GetCommandRestrictionRequest request, CancellationToken cancellationToken) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public async Task<IEnumerable<string>> Handle(GetCustomPrefixRequest request, Ca
.ToListAsync(),
TimeSpan.FromHours(12));

public Task<Unit> Handle(ClearCustomPrefixRequest request, CancellationToken cancellationToken)
public Task Handle(ClearCustomPrefixRequest request, CancellationToken cancellationToken)
{
_cache.Remove(GetCacheKey(request.Id));
return Unit.Task;
return Task.CompletedTask;
}

private static string GetCacheKey(ulong id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public async Task<IEnumerable<string>> Handle(GetCustomTagPrefixRequest request,
.ToListAsync(),
TimeSpan.FromHours(12));

public Task<Unit> Handle(ClearCustomTagPrefixRequest request, CancellationToken cancellationToken)
public Task Handle(ClearCustomTagPrefixRequest request, CancellationToken cancellationToken)
{
_cache.Remove(GetCacheKey(request.Id));
return Unit.Task;
return Task.CompletedTask;
}

private static string GetCacheKey(ulong id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ await _cache.GetOrAddAsync(GetCacheKey(request.Id, request.Designation),
.Where(x => x.Channel.Guild.Id == request.Id && x.Type == request.Designation)
.ToListAsync(), TimeSpan.FromHours(1));

public Task<Unit> Handle(ClearDesignatedChannelDetailRequest request, CancellationToken cancellationToken)
public Task Handle(ClearDesignatedChannelDetailRequest request, CancellationToken cancellationToken)
{
_cache.Remove(GetCacheKey(request.Id, request.Designation));
return Unit.Task;
return Task.CompletedTask;
}

private static string GetCacheKey(ulong id, Common.Enums.DesignatedChannels designation) =>
Expand Down
6 changes: 3 additions & 3 deletions ClemBot.Api/ClemBot.Api.Services/ClemBot.Api.Services.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>11</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LazyCache" Version="2.4.0" />
<PackageReference Include="MediatR" Version="11.0.0" />
<PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Quartz" Version="3.5.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
Expand Down
5 changes: 2 additions & 3 deletions ClemBot.Api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /ClemBot.Api

# Copy everything else and build
COPY . ./
RUN dotnet publish . -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /ClemBot.Api
RUN echo | ls .

COPY --from=build-env /ClemBot.Api/out .
ENTRYPOINT ["dotnet", "ClemBot.Api.Core.dll"]
Loading