From 8f36afdb6e4e817212094ad46f70798e251391ec Mon Sep 17 00:00:00 2001 From: Jay Madden Date: Sat, 27 Jan 2024 09:33:41 -0600 Subject: [PATCH] Upgrade api to dotnet 8 and associated dependencies (#873) --- .../ClemBot.Api.Common.csproj | 4 ++-- .../ClemBot.Api.Core/ClemBot.Api.Core.csproj | 17 ++++++++--------- ClemBot.Api/ClemBot.Api.Core/Program.cs | 12 ++++++++---- .../ClemBot.Api.Data/ClemBot.Api.Data.csproj | 16 ++++++++-------- .../Caching/Channels/ChannelCacheHandlers.cs | 9 ++++++--- .../Caching/Commands/CommandCacheHandler.cs | 4 ++-- .../Caching/CustomPrefix/CustomPrefixHandler.cs | 4 ++-- .../CustomTagPrefix/CustomTagPrefixHandlers.cs | 4 ++-- .../DesignatedChannelsDetailsCacheHandler.cs | 4 ++-- .../ClemBot.Api.Services.csproj | 6 +++--- ClemBot.Api/Dockerfile | 5 ++--- 11 files changed, 45 insertions(+), 40 deletions(-) diff --git a/ClemBot.Api/ClemBot.Api.Common/ClemBot.Api.Common.csproj b/ClemBot.Api/ClemBot.Api.Common/ClemBot.Api.Common.csproj index fbb844cc..0198568b 100644 --- a/ClemBot.Api/ClemBot.Api.Common/ClemBot.Api.Common.csproj +++ b/ClemBot.Api/ClemBot.Api.Common/ClemBot.Api.Common.csproj @@ -1,10 +1,10 @@ - net7.0 + net8.0 enable enable - 11 + 12 True diff --git a/ClemBot.Api/ClemBot.Api.Core/ClemBot.Api.Core.csproj b/ClemBot.Api/ClemBot.Api.Core/ClemBot.Api.Core.csproj index 990bfeb1..3bf439f8 100644 --- a/ClemBot.Api/ClemBot.Api.Core/ClemBot.Api.Core.csproj +++ b/ClemBot.Api/ClemBot.Api.Core/ClemBot.Api.Core.csproj @@ -1,12 +1,12 @@  - net7.0 + net8.0 Linux enable nullable 95286ed9-8628-45df-b16a-e46644da6b69 - 11 + 12 True @@ -16,17 +16,16 @@ - - - - + + + - + - - + + diff --git a/ClemBot.Api/ClemBot.Api.Core/Program.cs b/ClemBot.Api/ClemBot.Api.Core/Program.cs index 79cbf443..4397b1b9 100644 --- a/ClemBot.Api/ClemBot.Api.Core/Program.cs +++ b/ClemBot.Api/ClemBot.Api.Core/Program.cs @@ -108,10 +108,14 @@ builder.Services.AddScoped(); // 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(); + config.RegisterServicesFromAssemblyContaining(); + config.AddOpenBehavior(typeof(LoggingBehavior<,>)); + config.AddOpenBehavior(typeof(GuildSandboxAuthorizeBehavior<,>)); + config.AddOpenBehavior(typeof(CacheRequestBehavior<,>)); +}); // Specify Swagger startup options builder.Services.AddSwaggerGen(o => { diff --git a/ClemBot.Api/ClemBot.Api.Data/ClemBot.Api.Data.csproj b/ClemBot.Api/ClemBot.Api.Data/ClemBot.Api.Data.csproj index 28608ab4..c3b74404 100644 --- a/ClemBot.Api/ClemBot.Api.Data/ClemBot.Api.Data.csproj +++ b/ClemBot.Api/ClemBot.Api.Data/ClemBot.Api.Data.csproj @@ -1,24 +1,24 @@  - net7.0 + net8.0 9f2f92d0-9337-40e6-94dc-d7874e885acf True - 11 + 12 enable nullable - + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - + + + + + diff --git a/ClemBot.Api/ClemBot.Api.Services/Caching/Channels/ChannelCacheHandlers.cs b/ClemBot.Api/ClemBot.Api.Services/Caching/Channels/ChannelCacheHandlers.cs index 51895daa..1a30d09b 100644 --- a/ClemBot.Api/ClemBot.Api.Services/Caching/Channels/ChannelCacheHandlers.cs +++ b/ClemBot.Api/ClemBot.Api.Services/Caching/Channels/ChannelCacheHandlers.cs @@ -10,7 +10,7 @@ namespace ClemBot.Api.Services.Caching.Channels; public class ChannelCacheHandlers : - RequestHandler, + IRequestHandler, IRequestHandler { private readonly IAppCache _cache; @@ -28,8 +28,11 @@ public async Task 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}"; diff --git a/ClemBot.Api/ClemBot.Api.Services/Caching/Commands/CommandCacheHandler.cs b/ClemBot.Api/ClemBot.Api.Services/Caching/Commands/CommandCacheHandler.cs index ef8607a5..b49bb683 100644 --- a/ClemBot.Api/ClemBot.Api.Services/Caching/Commands/CommandCacheHandler.cs +++ b/ClemBot.Api/ClemBot.Api.Services/Caching/Commands/CommandCacheHandler.cs @@ -25,10 +25,10 @@ public CommandCacheHandler(IAppCache cache, ClemBotContext context) _context = context; } - public Task 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> Handle(GetCommandRestrictionRequest request, CancellationToken cancellationToken) => diff --git a/ClemBot.Api/ClemBot.Api.Services/Caching/CustomPrefix/CustomPrefixHandler.cs b/ClemBot.Api/ClemBot.Api.Services/Caching/CustomPrefix/CustomPrefixHandler.cs index 88b62513..4961221e 100644 --- a/ClemBot.Api/ClemBot.Api.Services/Caching/CustomPrefix/CustomPrefixHandler.cs +++ b/ClemBot.Api/ClemBot.Api.Services/Caching/CustomPrefix/CustomPrefixHandler.cs @@ -33,10 +33,10 @@ public async Task> Handle(GetCustomPrefixRequest request, Ca .ToListAsync(), TimeSpan.FromHours(12)); - public Task 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) diff --git a/ClemBot.Api/ClemBot.Api.Services/Caching/CustomTagPrefix/CustomTagPrefixHandlers.cs b/ClemBot.Api/ClemBot.Api.Services/Caching/CustomTagPrefix/CustomTagPrefixHandlers.cs index db09b42c..26c84911 100644 --- a/ClemBot.Api/ClemBot.Api.Services/Caching/CustomTagPrefix/CustomTagPrefixHandlers.cs +++ b/ClemBot.Api/ClemBot.Api.Services/Caching/CustomTagPrefix/CustomTagPrefixHandlers.cs @@ -33,10 +33,10 @@ public async Task> Handle(GetCustomTagPrefixRequest request, .ToListAsync(), TimeSpan.FromHours(12)); - public Task 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) diff --git a/ClemBot.Api/ClemBot.Api.Services/Caching/DesignatedChannels/DesignatedChannelsDetailsCacheHandler.cs b/ClemBot.Api/ClemBot.Api.Services/Caching/DesignatedChannels/DesignatedChannelsDetailsCacheHandler.cs index 5f990f1a..d766ca14 100644 --- a/ClemBot.Api/ClemBot.Api.Services/Caching/DesignatedChannels/DesignatedChannelsDetailsCacheHandler.cs +++ b/ClemBot.Api/ClemBot.Api.Services/Caching/DesignatedChannels/DesignatedChannelsDetailsCacheHandler.cs @@ -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 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) => diff --git a/ClemBot.Api/ClemBot.Api.Services/ClemBot.Api.Services.csproj b/ClemBot.Api/ClemBot.Api.Services/ClemBot.Api.Services.csproj index 572f5277..2984c3e8 100644 --- a/ClemBot.Api/ClemBot.Api.Services/ClemBot.Api.Services.csproj +++ b/ClemBot.Api/ClemBot.Api.Services/ClemBot.Api.Services.csproj @@ -1,14 +1,14 @@ - net7.0 - 11 + net8.0 + 12 True - + diff --git a/ClemBot.Api/Dockerfile b/ClemBot.Api/Dockerfile index 6c88b9af..8d7e0ac2 100644 --- a/ClemBot.Api/Dockerfile +++ b/ClemBot.Api/Dockerfile @@ -1,5 +1,5 @@ # 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 @@ -7,9 +7,8 @@ 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"]