Skip to content

Commit

Permalink
Upgrade to .NET 7 (#31)
Browse files Browse the repository at this point in the history
* Migrate to .net 7
  • Loading branch information
nkz-soft authored Nov 9, 2022
1 parent 9050bab commit 7fc8bea
Show file tree
Hide file tree
Showing 48 changed files with 191 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x
- name: Restore Dependencies
run: dotnet restore
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x
- name: Restore Dependencies
run: dotnet restore
- name: Build
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;

namespace NKZSoft.Template.Application.Common.Behaviours;

Expand All @@ -20,7 +20,7 @@ public PerformanceBehaviour(
_currentUserService = currentUserService;
}

public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
_timer.Start();

Expand All @@ -34,7 +34,7 @@ public async Task<TResponse> Handle(TRequest request, CancellationToken cancella
{
var requestName = typeof(TRequest).Name;
var user = _currentUserService.CurrentUser;

_logger.LogWarning("PerformanceBehaviour Long Running Request: {Name} ({ElapsedMilliseconds} milliseconds) {@UserId} {@Request}",
requestName, elapsedMilliseconds, user.Id, request);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NKZSoft.Template.Application.Common.Behaviours;
namespace NKZSoft.Template.Application.Common.Behaviours;

public class UnhandledExceptionBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : notnull, IRequest<TResponse>
{
Expand All @@ -9,7 +9,7 @@ public UnhandledExceptionBehaviour(ILogger<TRequest> logger)
_logger = logger;
}

public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NKZSoft.Template.Application.Common.Behaviours;
namespace NKZSoft.Template.Application.Common.Behaviours;

using Exceptions;

Expand All @@ -9,7 +9,7 @@ public class ValidationBehaviour<TRequest, TResponse> : IPipelineBehavior<TReque

public ValidationBehaviour(IEnumerable<IValidator<TRequest>> validators) => _validators = validators;

public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
if (_validators.Any())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
Expand All @@ -11,13 +11,13 @@

<ItemGroup>
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="6.1.0" />
<PackageReference Include="FluentResults" Version="3.14.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="10.3.4" />
<PackageReference Include="FluentResults" Version="3.15.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.2.2" />
<PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="Mapster.Async" Version="2.0.0" />
<PackageReference Include="Mapster.DependencyInjection" Version="1.0.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.10" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" />
</ItemGroup>


Expand Down
4 changes: 2 additions & 2 deletions src/NKZSoft.Template.Common/NKZSoft.Template.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace NKZSoft.Template.Domain.AggregatesModel.ToDoAggregates.Entities;

using System.Diagnostics.CodeAnalysis;
using Common;
using Events;

Expand All @@ -23,9 +24,9 @@ public ToDoItem(string title, string? note)
AddCreateDomainEvent();
}

public string Title { get; set; }
public string Title { get; private set; }

public string? Note { get; set; }
public string? Note { get; private set; }

public void Update(string title, string note)
{
Expand Down
6 changes: 3 additions & 3 deletions src/NKZSoft.Template.Domain/NKZSoft.Template.Domain.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
Expand All @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="10.0.1" />
<PackageReference Include="MediatR" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/NKZSoft.Template.Events/NKZSoft.Template.Events.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Version>1.0.0</Version>
<PackageVersion>1.0.0</PackageVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
Expand All @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -11,12 +11,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="MassTransit" Version="8.0.7" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="MassTransit" Version="8.0.8" />
<PackageReference Include="MassTransit.AspNetCore" Version="7.3.1" />
<PackageReference Include="MassTransit.Extensions.DependencyInjection" Version="7.3.1" />
<PackageReference Include="MassTransit.RabbitMQ" Version="8.0.7" />
<PackageReference Include="MassTransit.RabbitMQ" Version="8.0.8" />
<PackageReference Include="NKZSoft.Service.Configuration.MassTransit.RabbitMq" Version="1.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static IServiceCollection AddPersistence(this IServiceCollection services
var currentConfiguration = configuration.GetSection(DbConfigurationSection.SectionName)
.Get<DbConfigurationSection>();

currentConfiguration.ThrowIfNull(nameof(currentConfiguration));
ArgumentNullException.ThrowIfNull(currentConfiguration);
currentConfiguration.PostgresConnection.ThrowIfNull(nameof(currentConfiguration.PostgresConnection));
currentConfiguration.PostgresConnection?.ConnectionString.ThrowIfNull(nameof(currentConfiguration.PostgresConnection.ConnectionString));
currentConfiguration.PostgresConnection?.Database.ThrowIfNull(nameof(currentConfiguration.PostgresConnection.Database));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ private TContext Create(string basePath, string? environmentName)

var currentConfiguration = configuration.GetSection(DbConfigurationSection.SectionName)
.Get<PostgresConnection>();

ArgumentNullException.ThrowIfNull(currentConfiguration);

var connectionString = $"{currentConfiguration.ConnectionString}Database=${currentConfiguration.Database}";

return Create(connectionString);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -13,21 +13,21 @@

<ItemGroup>
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="6.1.0" />
<PackageReference Include="MediatR" Version="10.0.1" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.10">
<PackageReference Include="MediatR" Version="11.0.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Design" Version="1.1.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" 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.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0-rc.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
<PackageReference Include="Scrutor" Version="4.2.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Version>1.0.2</Version>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -15,12 +15,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.21.7" />
<PackageReference Include="Google.Protobuf" Version="3.21.9" />
<PackageReference Include="protobuf-net" Version="3.1.22" />
<PackageReference Include="protobuf-net.Grpc.AspNetCore" Version="1.0.177" />
<PackageReference Include="protobuf-net.Grpc.AspNetCore.Reflection" Version="1.0.177" />
<PackageReference Include="protobuf-net.Reflection" Version="3.1.22" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.7.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.10.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Version>1.0.2</Version>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
Expand All @@ -11,9 +11,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HotChocolate.AspNetCore" Version="12.15.0" />
<PackageReference Include="HotChocolate.Data" Version="12.15.0" />
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="12.15.0" />
<PackageReference Include="HotChocolate.AspNetCore" Version="12.15.2" />
<PackageReference Include="HotChocolate.Data" Version="12.15.2" />
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="12.15.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NKZSoft.Template.Presentation.REST.Extensions;
namespace NKZSoft.Template.Presentation.REST.Extensions;

using Filters;

Expand All @@ -9,6 +9,8 @@ public static IServiceCollection AddRestPresentation(
{
var corsParams = configuration.GetSection("Cors").Get<List<string>>();

ArgumentNullException.ThrowIfNull(corsParams);

services.AddCors(o => o.AddPolicy("CorsPolicy", builder =>
{
builder.WithOrigins(corsParams.ToArray())
Expand All @@ -21,8 +23,6 @@ public static IServiceCollection AddRestPresentation(
.AddSwagger(configuration, Assembly.GetExecutingAssembly())
.AddValidatorsFromAssemblyContaining<IApplicationDbContext>(ServiceLifetime.Scoped, null, true)
.AddControllers(options => options.Filters.Add<CustomExceptionFilterAttribute>())
.AddNewtonsoftJson(options =>
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore)
.AddApplicationPart(Assembly.GetExecutingAssembly());

return services;
Expand Down
1 change: 1 addition & 0 deletions src/NKZSoft.Template.Presentation.REST/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
global using System.Threading.Tasks;
global using System.Collections.Generic;
global using System.Linq;
global using System.Text.Json;
global using System.Threading;
global using Microsoft.AspNetCore.Hosting;
global using Microsoft.Extensions.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ namespace NKZSoft.Template.Presentation.REST.Middleware;

using Models;
using Models.Result;
using Newtonsoft.Json;

using ILogger = Microsoft.Extensions.Logging.ILogger;

Expand Down Expand Up @@ -36,7 +35,7 @@ private static async Task HandleExceptionAsync(HttpContext context, ILogger log,
const HttpStatusCode code = HttpStatusCode.InternalServerError;
var resultDto = new ResultDto<Unit>(Unit.Value, false, new[] { new ErrorDto(exception.Message, code.ToString()) });

var result = JsonConvert.SerializeObject(resultDto);
var result = JsonSerializer.Serialize(resultDto);
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
await context.Response.WriteAsync(result);
Expand Down
22 changes: 20 additions & 2 deletions src/NKZSoft.Template.Presentation.REST/Models/Result/ResultDto.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace NKZSoft.Template.Presentation.REST.Models.Result;

using System.Text.Json.Serialization;

[JsonDerivedType(typeof(ResultDto<>), "ResultDto")]
public record ResultDtoBase(bool IsSuccess, IEnumerable<ErrorDto> Errors)
{
public static ResultDto<Unit> CreateFromErrors(IList<KeyValuePair<string, string>> errors)
Expand All @@ -22,5 +25,20 @@ public static ResultDto<Unit> CreateFromErrors(string errors, HttpStatusCode sta
}
}

public sealed record ResultDto<T>(T Data, bool IsSuccess, IEnumerable<ErrorDto> Errors) :
ResultDtoBase(IsSuccess, Errors);
public sealed record ResultDto<T> : ResultDtoBase
{
[JsonConstructor]
public ResultDto(T Data, bool IsSuccess, IEnumerable<ErrorDto> Errors) : base(IsSuccess, Errors)
{
this.Data = Data;
}

public T Data { get; init; }

public void Deconstruct(out T Data, out bool IsSuccess, out IEnumerable<ErrorDto> Errors)
{
Data = this.Data;
IsSuccess = this.IsSuccess;
Errors = this.Errors;
}
}
Loading

0 comments on commit 7fc8bea

Please sign in to comment.