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

Migrated to .NET 8. Updated NuGet versions #4

Merged
merged 8 commits into from
Jan 1, 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
2 changes: 1 addition & 1 deletion .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Install dotnet-ef
run: dotnet tool install --global dotnet-ef
Expand Down
13 changes: 5 additions & 8 deletions Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
</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">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="DomainResult" Version="3.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<!-- The EF references below are required for generating the migration script only -->
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.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
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using AK.DbSample.Database;

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace AK.DbSample.Domain.Configuration;
namespace AK.DbSample.Database.Configuration;

public static partial class ServiceCollectionExtensions
{
Expand Down
4 changes: 1 addition & 3 deletions Database/DataContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AK.DbSample.Database.Entities;
using AK.DbSample.Database.Infrastructure;

using Microsoft.EntityFrameworkCore;

Expand All @@ -20,8 +19,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Date is a DateOnly property and date on database
builder.Property(x => x.Date)
// These converters are still required in EF 7 (https://github.com/dotnet/efcore/issues/24507)
.HasConversion<DateOnlyConverter, DateOnlyComparer>();
.HasColumnType("date");

// Set cascade delete
builder.HasOne(p => p.Client)
Expand Down
5 changes: 2 additions & 3 deletions Database/Database.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
</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.SqlServer" Version="8.0.0" />
</ItemGroup>
</Project>
29 changes: 0 additions & 29 deletions Database/Infrastructure/DateOnlyComparer.cs

This file was deleted.

34 changes: 0 additions & 34 deletions Database/Infrastructure/DateOnlyConverter.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Database/Migrations/20220322114144_InititalCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
{
Number = table.Column<string>(type: "nvarchar(100)", nullable: false),
ClientId = table.Column<long>(type: "bigint", nullable: false),
Date = table.Column<DateTime>(type: "datetime", nullable: false),
Date = table.Column<DateOnly>(type: "date", nullable: false),
Amount = table.Column<decimal>(type: "decimal(18,2)", nullable: false)
},
constraints: table =>
Expand Down
11 changes: 0 additions & 11 deletions DbSample.csproj

This file was deleted.

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
20 changes: 9 additions & 11 deletions Domain.Tests/Domain.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@
</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.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
15 changes: 5 additions & 10 deletions Domain.Tests/TestDbBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AK.DbSample.Database;
using AK.DbSample.Database.Configuration;
using AK.DbSample.Database.Entities;
using AK.DbSample.Domain.Configuration;

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
Expand All @@ -20,21 +20,16 @@ namespace AK.DbSample.Domain.Tests;
/// Base test class with a DI container and DB connection.
/// Derive from it when need DI and DB connection
/// </summary>
public abstract class TestDbBase : TestBase, IAsyncLifetime
public abstract class TestDbBase(ITestOutputHelper output) : TestBase, IAsyncLifetime
{
protected DataContext DataContext => Container.GetRequiredService<DataContext>();
protected readonly ITestOutputHelper Output;
protected readonly ITestOutputHelper Output = output;

/// <summary>
/// Tables that shouldn't be touched on whipping out the DB
/// </summary>
private readonly Table[] _tablesToIgnore = { Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.DefaultTableName /* "__EFMigrationsHistory" */ };
private readonly Table[] _tablesToIgnore = [Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.DefaultTableName /* "__EFMigrationsHistory" */];

protected TestDbBase(ITestOutputHelper output)
{
Output = output;
}

/// <summary>
/// Configure the DI container
/// </summary>
Expand Down Expand Up @@ -83,7 +78,7 @@ public async Task InitializeAsync()
/// <summary>
/// Wipe out all data in the database
/// </summary>
protected async Task WipeOutDbAsync()
private async Task WipeOutDbAsync()
{
Respawner? respawn = null;
try
Expand Down
7 changes: 4 additions & 3 deletions Domain/Configuration/AddAndConfigureDomainServices.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using AK.DbSample.Database.Configuration;
using AK.DbSample.Domain.Helpers;
using AK.DbSample.Domain.Services;

using Microsoft.Extensions.DependencyInjection;

namespace AK.DbSample.Domain.Configuration;

public static partial class ServiceCollectionExtensions
public static 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 +20,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);
}
}
4 changes: 2 additions & 2 deletions Domain/Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

<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" />
</ItemGroup>

</Project>
9 changes: 2 additions & 7 deletions Domain/Services/BaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

namespace AK.DbSample.Domain.Services;

public abstract class BaseService
public abstract class BaseService(DataContext dataContext)
{
protected readonly DataContext DataContext;

protected BaseService(DataContext dataContext)
{
DataContext = dataContext;
}
protected readonly DataContext DataContext = dataContext;
}
4 changes: 1 addition & 3 deletions Domain/Services/Client/ClientCommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ public interface IClientCommandService
Task<IDomainResult> Delete(long id);
}

public class ClientCommandService: BaseService, IClientCommandService
public class ClientCommandService(DataContext dataContext) : BaseService(dataContext), IClientCommandService
{
public ClientCommandService(DataContext dataContext) : base(dataContext) {}

public async Task<(long, IDomainResult)> Create(CreateUpdateClientRequest dto)
{
var nameCheckResult = await UniqueNameCheck(null, dto.Name);
Expand Down
4 changes: 1 addition & 3 deletions Domain/Services/Client/ClientQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
Task<GetClientListResponse[]> GetList(GetClientListRequest filter);
}

public class ClientQueryService: BaseService, IClientQueryService
public class ClientQueryService(DataContext dataContext) : BaseService(dataContext), IClientQueryService
{
public ClientQueryService(DataContext dataContext) : base(dataContext) {}

public async Task<(GetClientByIdResponse, IDomainResult)> GetById(long clientId)
{
var client = await DataContext.Clients
Expand All @@ -36,7 +34,7 @@
select new GetClientListResponse(
c.Id,
c.Name,
c.Invoices

Check warning on line 37 in Domain/Services/Client/ClientQueryService.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 37 in Domain/Services/Client/ClientQueryService.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 37 in Domain/Services/Client/ClientQueryService.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 37 in Domain/Services/Client/ClientQueryService.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
.OrderByDescending(i => i.Date)
.Take(1)
.SingleOrDefault().Date
Expand Down
1 change: 1 addition & 0 deletions Domain/Services/Client/DTOs/ClientQueryDtos.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ReSharper disable NotAccessedPositionalProperty.Global
namespace AK.DbSample.Domain.Services.Client.DTOs;

public record GetClientListRequest(string? Name = null);
Expand Down
1 change: 1 addition & 0 deletions Domain/Services/Invoice/DTOs/InvoiceQueryDtos.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ReSharper disable NotAccessedPositionalProperty.Global
namespace AK.DbSample.Domain.Services.Invoice.DTOs;

public record GetInvoiceListRequest(long? ClientId = null);
Expand Down
4 changes: 1 addition & 3 deletions Domain/Services/Invoice/InvoiceCommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ public interface IInvoiceCommandService
Task<IDomainResult> Delete(string number);
}

public class InvoiceCommandService: BaseService, IInvoiceCommandService
public class InvoiceCommandService(DataContext dataContext) : BaseService(dataContext), IInvoiceCommandService
{
public InvoiceCommandService(DataContext dataContext) : base(dataContext) {}

public async Task<(string, IDomainResult)> Create(CreateInvoiceRequest dto)
{
var numberCheckResult = await UniqueNumberCheck(dto.Number, true);
Expand Down
4 changes: 1 addition & 3 deletions Domain/Services/Invoice/InvoiceQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ public interface IInvoiceQueryService
Task<GetInvoiceListResponse[]> GetList(GetInvoiceListRequest filter);
}

public class InvoiceQueryService: BaseService, IInvoiceQueryService
public class InvoiceQueryService(DataContext dataContext) : BaseService(dataContext), IInvoiceQueryService
{
public InvoiceQueryService(DataContext dataContext) : base(dataContext) {}

public async Task<(GetInvoiceByNumberResponse, IDomainResult)> GetByNumber(string number)
{
var invoice = await DataContext.Invoices
Expand Down
Loading
Loading