Skip to content

Commit 78a3d74

Browse files
committed
Upgrade to .net 9.0
1 parent f7142df commit 78a3d74

30 files changed

Lines changed: 352 additions & 417 deletions

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1616
- name: Setup .NET
17-
uses: actions/setup-dotnet@v1
17+
uses: actions/setup-dotnet@v4
1818
with:
19-
dotnet-version: 5.0.x
19+
dotnet-version: 9.0.x
2020
- name: Restore dependencies
2121
run: dotnet restore
2222
- name: Build

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,7 @@ MigrationBackup/
349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351351
/Api/appsettings.Development.json
352+
353+
# JetBrains Rider
354+
*.sln.iml
355+
.idea/*

Api/Api.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
9-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
10-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
11-
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
12-
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
13-
<PackageReference Include="Serilog" Version="2.10.0" />
14-
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
15-
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
16-
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
17-
<PackageReference Include="Serilog.Sinks.Udp" Version="7.1.0" />
18-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
19-
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.4" />
8+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.8" />
9+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.8" />
10+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.8" />
11+
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.8" />
12+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.8" />
13+
<PackageReference Include="Serilog" Version="4.3.0" />
14+
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
15+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
16+
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
17+
<PackageReference Include="Serilog.Sinks.Udp" Version="10.0.0" />
18+
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
19+
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="9.0.3" />
2020
<PackageReference Include="System.Net.Http" Version="4.3.4" />
2121
</ItemGroup>
2222

Api/Controllers/DummyController.cs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,32 @@
33
using System.Threading;
44
using System.Threading.Tasks;
55
using Api.Validators;
6+
using Domain.Abstractions;
67
using Domain.Models;
7-
using Domain.Ports;
88
using Microsoft.AspNetCore.Http;
99
using Swashbuckle.AspNetCore.Annotations;
1010

11-
namespace Api.Controllers
11+
namespace Api.Controllers;
12+
13+
[ApiController]
14+
[Route("[controller]")]
15+
public class DummyController : ControllerBase
1216
{
13-
[ApiController]
14-
[Route("[controller]")]
15-
public class DummyController : ControllerBase
16-
{
17-
private readonly IDummyService _service;
17+
private readonly IDummyService _service;
1818

19-
public DummyController(IDummyService service)
20-
{
21-
_service = service;
22-
}
19+
public DummyController(IDummyService service)
20+
{
21+
_service = service;
22+
}
2323

24-
[HttpGet]
25-
[Route("website")]
26-
[SwaggerOperation("Get website infos")]
27-
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
28-
[ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
29-
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
30-
public Task<WebSite> GetWebSiteAsync([Required][UrlValidator] string url = "https://abc.com/", CancellationToken cancellationToken = default)
31-
{
32-
return _service.GetWebSiteAsync(url, cancellationToken);
33-
}
24+
[HttpGet]
25+
[Route("website")]
26+
[SwaggerOperation("Get website infos")]
27+
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
28+
[ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
29+
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
30+
public Task<WebSite> GetWebSiteAsync([Required][UrlValidator] string url = "https://abc.com/", CancellationToken cancellationToken = default)
31+
{
32+
return _service.GetWebSiteAsync(url, cancellationToken);
3433
}
35-
}
34+
}

Api/Filters/ApiExceptionFilter.cs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,32 @@
33
using Microsoft.AspNetCore.Mvc;
44
using Microsoft.AspNetCore.Mvc.Filters;
55

6-
namespace Api.Filters
6+
namespace Api.Filters;
7+
8+
public sealed class ApiExceptionFilter : ExceptionFilterAttribute
79
{
8-
public sealed class ApiExceptionFilter : ExceptionFilterAttribute
10+
public override void OnException(ExceptionContext context)
911
{
10-
public override void OnException(ExceptionContext context)
11-
{
12-
var exception = context?.Exception;
12+
var exception = context.Exception;
1313

14-
if (exception != null && IsBadRequest(exception))
14+
if (IsBadRequest(exception))
15+
{
16+
var errorMessage = exception.Message;
17+
var errorName = exception.GetType().Name;
18+
var error = new
1519
{
16-
var errorMessage = exception.Message;
17-
var errorName = exception.GetType().Name;
18-
var error = new
19-
{
20-
ErrorName = errorName,
21-
ErrorMessage = errorMessage
22-
};
23-
context.Result = new BadRequestObjectResult(error);
24-
context.ModelState.AddModelError(errorName, errorMessage);
25-
}
26-
27-
base.OnException(context);
20+
ErrorName = errorName,
21+
ErrorMessage = errorMessage
22+
};
23+
context.Result = new BadRequestObjectResult(error);
24+
context.ModelState.AddModelError(errorName, errorMessage);
2825
}
2926

30-
private static bool IsBadRequest(Exception exception)
31-
{
32-
return exception is BusinessValidationException;
33-
}
27+
base.OnException(context);
28+
}
29+
30+
private static bool IsBadRequest(Exception exception)
31+
{
32+
return exception is BusinessValidationException;
3433
}
35-
}
34+
}

Api/Program.cs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,28 @@
44
using Serilog;
55
using Serilog.Debugging;
66

7-
namespace Api
7+
namespace Api;
8+
9+
public static class Program
810
{
9-
public class Program
11+
public static void Main(string[] args)
1012
{
11-
public static void Main(string[] args)
12-
{
13-
CreateHostBuilder(args).Build().Run();
14-
}
15-
16-
public static IHostBuilder CreateHostBuilder(string[] args) =>
17-
Host.CreateDefaultBuilder(args)
18-
.ConfigureWebHostDefaults(webHostBuilder =>
19-
{
20-
webHostBuilder.UseStartup<Startup>();
21-
webHostBuilder.CaptureStartupErrors(true);
22-
webHostBuilder.UseSetting(WebHostDefaults.DetailedErrorsKey, "true");
23-
})
24-
.UseSerilog((hostingContext, loggerConfiguration) =>
25-
{
26-
SelfLog.Enable(Console.Error);
27-
loggerConfiguration
28-
.ReadFrom.Configuration(hostingContext.Configuration)
29-
.Enrich.FromLogContext();
30-
});
13+
CreateHostBuilder(args).Build().Run();
3114
}
32-
}
15+
16+
private static IHostBuilder CreateHostBuilder(string[] args) =>
17+
Host.CreateDefaultBuilder(args)
18+
.ConfigureWebHostDefaults(webHostBuilder =>
19+
{
20+
webHostBuilder.UseStartup<Startup>();
21+
webHostBuilder.CaptureStartupErrors(true);
22+
webHostBuilder.UseSetting(WebHostDefaults.DetailedErrorsKey, "true");
23+
})
24+
.UseSerilog((hostingContext, loggerConfiguration) =>
25+
{
26+
SelfLog.Enable(Console.Error);
27+
loggerConfiguration
28+
.ReadFrom.Configuration(hostingContext.Configuration)
29+
.Enrich.FromLogContext();
30+
});
31+
}

Api/Startup.Ioc.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
1+
using Domain.Abstractions;
12
using Domain.Configuration;
2-
using Domain.Ports;
33
using Domain.Services;
44
using Infrastructure.DistributedCaches;
55
using Infrastructure.HttpClients;
66
using Microsoft.Extensions.DependencyInjection;
77

8-
namespace Api
8+
namespace Api;
9+
10+
public partial class Startup
911
{
10-
public partial class Startup
12+
private void ConfigureIoc(IServiceCollection services)
1113
{
12-
private void ConfigureIoc(IServiceCollection services)
13-
{
14-
services.AddScoped<DummyMessageHandler>();
15-
16-
services.AddScoped<IDummyService, DummyService>();
14+
services.AddScoped<DummyMessageHandler>();
1715

18-
services.AddHttpClient<IDummyClient, DummyClient>()
19-
.AddHttpMessageHandler<DummyMessageHandler>();
16+
services.AddScoped<IDummyService, DummyService>();
2017

21-
services.AddDistributedMemoryCache();
18+
services
19+
.AddHttpClient<IDummyClient, DummyClient>()
20+
.AddHttpMessageHandler<DummyMessageHandler>();
2221

23-
services.AddTransient<IDistributedCacheProvider, DistributedCacheProvider>();
22+
services.AddDistributedMemoryCache();
2423

25-
services.AddSingleton<IWebSiteCacheProvider, WebSiteCacheProvider>();
24+
services.AddSingleton<IDistributedCacheProvider, DistributedCacheProvider>();
2625

27-
services.Configure<Settings>(Configuration.GetSection(nameof(Settings)));
26+
services.Configure<Settings>(Configuration.GetSection(nameof(Settings)));
2827

29-
services.Configure<DistributedCacheOptions>(Configuration.GetSection(nameof(DistributedCacheOptions)));
30-
}
28+
services.Configure<DistributedCacheOptions>(Configuration.GetSection(nameof(DistributedCacheOptions)));
3129
}
32-
}
30+
}

Api/Startup.Swagger.cs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,31 @@
22
using Microsoft.Extensions.DependencyInjection;
33
using Microsoft.OpenApi.Models;
44

5-
namespace Api
5+
namespace Api;
6+
7+
public partial class Startup
68
{
7-
public partial class Startup
8-
{
9-
private const string ApiName = "Api";
10-
private const string CurrentVersion = "v1";
11-
private static readonly string Url = $"{CurrentVersion}/swagger.json";
12-
private static readonly OpenApiInfo Info = new() { Title = ApiName, Version = CurrentVersion };
9+
private const string ApiName = "Api";
10+
private const string CurrentVersion = "v1";
11+
private const string Url = $"{CurrentVersion}/swagger.json";
12+
private static readonly OpenApiInfo Info = new() { Title = ApiName, Version = CurrentVersion };
1313

14-
private static void ConfigureSwagger(IServiceCollection services)
14+
private static void ConfigureSwagger(IServiceCollection services)
15+
{
16+
services.AddSwaggerGen(options =>
1517
{
16-
services.AddSwaggerGen(options =>
17-
{
18-
options.EnableAnnotations();
19-
options.SwaggerDoc(CurrentVersion, Info);
20-
});
21-
}
18+
options.EnableAnnotations();
19+
options.SwaggerDoc(CurrentVersion, Info);
20+
});
21+
}
2222

23-
private static void UseSwagger(IApplicationBuilder app)
23+
private static void UseSwagger(IApplicationBuilder app)
24+
{
25+
app.UseSwagger();
26+
app.UseSwaggerUI(c =>
2427
{
25-
app.UseSwagger();
26-
app.UseSwaggerUI(c =>
27-
{
28-
c.DisplayRequestDuration();
29-
c.SwaggerEndpoint(Url, ApiName);
30-
});
31-
}
28+
c.DisplayRequestDuration();
29+
c.SwaggerEndpoint(Url, ApiName);
30+
});
3231
}
33-
}
32+
}

0 commit comments

Comments
 (0)