From 6c8fd0a1140b59e1047c2fa7f11ff7f94612707b Mon Sep 17 00:00:00 2001 From: Alex Klaus Date: Mon, 1 Jan 2024 11:49:11 +1000 Subject: [PATCH] Migrated to .NET 8. Updated NuGet versions --- Api/Api.csproj | 8 +++---- Api/Configuration/AddAndConfigureSwagger.cs | 9 ++++---- Api/Startup.cs | 14 +++--------- Database/Database.csproj | 6 ++--- Directory.Build.props | 2 +- Domain.Tests/Domain.Tests.csproj | 22 +++++++++---------- .../AddAndConfigureDomainServices.cs | 4 ++-- Domain/Domain.csproj | 5 +++-- README.md | 6 ++--- devops/start_docker_sql_server_with_new_db.sh | 2 +- 10 files changed, 35 insertions(+), 43 deletions(-) diff --git a/Api/Api.csproj b/Api/Api.csproj index 43bcf47..201773a 100644 --- a/Api/Api.csproj +++ b/Api/Api.csproj @@ -6,14 +6,12 @@ - - - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Api/Configuration/AddAndConfigureSwagger.cs b/Api/Configuration/AddAndConfigureSwagger.cs index 6d10747..7e5c00f 100644 --- a/Api/Configuration/AddAndConfigureSwagger.cs +++ b/Api/Configuration/AddAndConfigureSwagger.cs @@ -2,14 +2,15 @@ namespace AK.DbSample.Api.Configuration; internal static partial class ServiceCollectionExtensions { - public static void AddAndConfigureSwagger(this IServiceCollection services, IWebHostEnvironment env) + public static IServiceCollection AddAndConfigureSwagger(this IServiceCollection services, IWebHostEnvironment env) { if (env.IsProduction()) // No Swagger for PROD - return; + return services; - services.AddEndpointsApiExplorer(); - services.AddSwaggerGen(c => c.UseDateOnlyTimeOnlyStringConverters()); + return services + .AddEndpointsApiExplorer() + .AddSwaggerGen(); } public static void AddAppSwaggerUi(this IApplicationBuilder app, IWebHostEnvironment env) diff --git a/Api/Startup.cs b/Api/Startup.cs index 0f9121b..61d3e38 100644 --- a/Api/Startup.cs +++ b/Api/Startup.cs @@ -18,18 +18,10 @@ public Startup(IConfiguration config, IWebHostEnvironment hostEnvironment) public void ConfigureServices(IServiceCollection services) { var settings = services.AddAndConfigureAppSettings(_configuration); - - services.AddAndConfigureDomainServices((settings.ConnectionString, true)); - - // The below converters were required for .NET 6. Since .NET 7 they work out-of-the-box, - // Swashbuckle is still lacking behind with the standard support, so need to keep these lines - // till Swashbuckle NuGet gets updated. - // Note: It'll also eliminate the need in DateOnlyTimeOnly.AspNet NuGet (https://github.com/maxkoshevoi/DateOnlyTimeOnly.AspNet) - services - .AddControllers(options => options.UseDateOnlyTimeOnlyStringConverters()) - .AddJsonOptions(options => options.UseDateOnlyTimeOnlyStringConverters()); - services.AddAndConfigureSwagger(_hostingEnvironment); + services.AddAndConfigureDomainServices((settings.ConnectionString, true)) + .AddAndConfigureSwagger(_hostingEnvironment) + .AddControllers(); } public void Configure(IApplicationBuilder app) diff --git a/Database/Database.csproj b/Database/Database.csproj index 6ccf22a..b91d1aa 100644 --- a/Database/Database.csproj +++ b/Database/Database.csproj @@ -6,8 +6,8 @@ - - - + + + diff --git a/Directory.Build.props b/Directory.Build.props index 36a00cc..fe3af31 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - net7.0 + net8.0 latest enable strict diff --git a/Domain.Tests/Domain.Tests.csproj b/Domain.Tests/Domain.Tests.csproj index 008a5fc..96f5bcf 100644 --- a/Domain.Tests/Domain.Tests.csproj +++ b/Domain.Tests/Domain.Tests.csproj @@ -7,23 +7,23 @@ - - - - - - - - - + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/Domain/Configuration/AddAndConfigureDomainServices.cs b/Domain/Configuration/AddAndConfigureDomainServices.cs index 58b93c9..1a95404 100644 --- a/Domain/Configuration/AddAndConfigureDomainServices.cs +++ b/Domain/Configuration/AddAndConfigureDomainServices.cs @@ -7,7 +7,7 @@ namespace AK.DbSample.Domain.Configuration; public static partial class ServiceCollectionExtensions { - public static void AddAndConfigureDomainServices(this IServiceCollection services, (string? connectionString, bool registerMigrationsAssembly)? configureDatabase = null) + public static IServiceCollection AddAndConfigureDomainServices(this IServiceCollection services, (string? connectionString, bool registerMigrationsAssembly)? configureDatabase = null) { if (configureDatabase.HasValue) services.AddAndConfigureDbContext(configureDatabase.Value.connectionString, configureDatabase.Value.registerMigrationsAssembly); @@ -19,6 +19,6 @@ public static void AddAndConfigureDomainServices(this IServiceCollection service && t.IsAssignableTo() // All services ).ToList(); - services.RegisterAsImplementedInterfaces(types, ServiceLifetime.Scoped); + return services.RegisterAsImplementedInterfaces(types, ServiceLifetime.Scoped); } } \ No newline at end of file diff --git a/Domain/Domain.csproj b/Domain/Domain.csproj index 6411d1a..19d9d4c 100644 --- a/Domain/Domain.csproj +++ b/Domain/Domain.csproj @@ -7,13 +7,14 @@ + all - - + + diff --git a/README.md b/README.md index 91b0306..1317416 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ See "[Pain & Gain of automated tests against SQL (MS SQL or PostgreSQL)](https:/ ### Technologies - Main project: - - [.NET 7](https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-7); - - [Entity Framework Core 7](https://docs.microsoft.com/en-us/ef/core/) and [dotnet-ef](https://docs.microsoft.com/en-us/ef/core/cli/dotnet) CLI. + - [.NET 8](https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8); + - [Entity Framework Core 8](https://docs.microsoft.com/en-us/ef/core/) and [dotnet-ef](https://docs.microsoft.com/en-us/ef/core/cli/dotnet) CLI. - Test project: - [xUnit](https://xunit.net/) + [Respawn](https://github.com/jbogard/Respawn); - [Docker](https://www.docker.com/) + [SQL Server image](https://hub.docker.com/_/microsoft-mssql-server). @@ -34,7 +34,7 @@ See "[Pain & Gain of automated tests against SQL (MS SQL or PostgreSQL)](https:/ ## Getting Started (locally) Firstly, check out this Git repo and install dependencies: - - [.NET SDK](https://dotnet.microsoft.com/download) v7.x; + - [.NET SDK](https://dotnet.microsoft.com/download) v8.x; - [dotnet-ef](https://docs.microsoft.com/en-us/ef/core/cli/dotnet) CLI; - [Docker](https://www.docker.com/). diff --git a/devops/start_docker_sql_server_with_new_db.sh b/devops/start_docker_sql_server_with_new_db.sh index b4344fb..ee534f7 100755 --- a/devops/start_docker_sql_server_with_new_db.sh +++ b/devops/start_docker_sql_server_with_new_db.sh @@ -4,7 +4,7 @@ saPassword="Secret_Passw0rd" dbName="SampleDb" if [ -z "$1" ]; then - echo "Provide path to a SQL script for creating DB schema" + echo "ERROR! No path to a SQL script for creating DB schema. Provide as a parameter" exit 1 fi createDbSqlScript="$1"