Skip to content

Commit

Permalink
Migrated to .NET 8. Updated NuGet versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Klaus committed Jan 1, 2024
1 parent ebee547 commit 6c8fd0a
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 43 deletions.
8 changes: 3 additions & 5 deletions Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DateOnlyTimeOnly.AspNet" Version="2.0.0" />
<PackageReference Include="DateOnlyTimeOnly.AspNet.Swashbuckle" Version="2.0.0" />
<PackageReference Include="DomainResult" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.1">
<PackageReference Include="DomainResult" Version="3.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions Api/Configuration/AddAndConfigureSwagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 3 additions & 11 deletions Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions Database/Database.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<Features>strict</Features>
Expand Down
22 changes: 11 additions & 11 deletions Domain.Tests/Domain.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Respawn" Version="6.0.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Respawn" Version="6.1.0" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions Domain/Configuration/AddAndConfigureDomainServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -19,6 +19,6 @@ public static void AddAndConfigureDomainServices(this IServiceCollection service
&& t.IsAssignableTo<BaseService>() // All services
).ToList();

services.RegisterAsImplementedInterfaces(types, ServiceLifetime.Scoped);
return services.RegisterAsImplementedInterfaces(types, ServiceLifetime.Scoped);
}
}
5 changes: 3 additions & 2 deletions Domain/Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

<ItemGroup>
<ProjectReference Include="..\Database\Database.csproj">
<!-- Prevent exposing the DB entities to the projects referring to `Domain` (e.g. `API` proj) -->
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="DomainResult.Common" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.1" />
<PackageReference Include="DomainResult.Common" Version="3.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ 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).

## 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/).

Expand Down
2 changes: 1 addition & 1 deletion devops/start_docker_sql_server_with_new_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6c8fd0a

Please sign in to comment.