chore: upgrade to ASP.NET Core 8
This commit is contained in:
@@ -13,7 +13,7 @@ on:
|
||||
- "**/*.yml"
|
||||
|
||||
env:
|
||||
DOTNET_VERSION: "7.0.x"
|
||||
DOTNET_VERSION: "8.0.x"
|
||||
DOTNET_NOLOGO: true
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: true
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
|
||||
|
||||
+33
-33
@@ -15,40 +15,40 @@
|
||||
<PackageVersion Include="Bogus" Version="34.0.2" />
|
||||
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
|
||||
<PackageVersion Include="EntityFrameworkCore.DataEncryption" Version="4.0.1" />
|
||||
<PackageVersion Include="EntityFrameworkCore.DataEncryption" Version="5.0.0" />
|
||||
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="11.8.0" />
|
||||
<PackageVersion Include="FluentValidation" Version="11.8.0" />
|
||||
<PackageVersion Include="MediatR" Version="12.1.1" />
|
||||
<PackageVersion Include="MediatR" Version="12.2.0" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.13" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.1.0" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Analyzers" Version="7.0.13" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.13" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.13" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.13" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.13" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Analyzers" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Caching.Redis" Version="2.2.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="7.0.13" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.13" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="7.0.13" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Http" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Identity.Core" Version="7.0.13" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Options.DataAnnotations" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Options" Version="7.0.1" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Primitives" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Identity.Core" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Primitives" Version="8.0.0" />
|
||||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
||||
<PackageVersion Include="MiniProfiler.AspNetCore.Mvc" Version="4.3.8" />
|
||||
@@ -57,13 +57,13 @@
|
||||
<PackageVersion Include="MongoDB.Driver" Version="2.22.0" />
|
||||
<PackageVersion Include="NSubstitute.Analyzers.CSharp" Version="1.0.16" />
|
||||
<PackageVersion Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageVersion Include="Polly" Version="8.1.0" />
|
||||
<PackageVersion Include="Polly" Version="8.2.0" />
|
||||
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
|
||||
<PackageVersion Include="System.Text.Json" Version="7.0.3" />
|
||||
<PackageVersion Include="xunit.analyzers" Version="1.4.0" />
|
||||
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
|
||||
<PackageVersion Include="System.Text.Json" Version="8.0.0" />
|
||||
<PackageVersion Include="xunit.analyzers" Version="1.6.0" />
|
||||
<PackageVersion Include="xunit.categories" Version="2.0.8" />
|
||||
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||
<PackageVersion Include="xunit" Version="2.6.1" />
|
||||
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.4" />
|
||||
<PackageVersion Include="xunit" Version="2.6.2" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "7.0.402",
|
||||
"version": "8.0.100",
|
||||
"rollForward": "latestMajor",
|
||||
"allowPrerelease": false
|
||||
}
|
||||
|
||||
@@ -7,12 +7,10 @@ using Shop.Core.Extensions;
|
||||
|
||||
namespace Shop.Application.Behaviors;
|
||||
|
||||
public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
|
||||
public class LoggingBehavior<TRequest, TResponse>(ILogger<LoggingBehavior<TRequest, TResponse>> logger) : IPipelineBehavior<TRequest, TResponse>
|
||||
where TRequest : IRequest<TResponse>
|
||||
{
|
||||
private readonly ILogger<LoggingBehavior<TRequest, TResponse>> _logger;
|
||||
|
||||
public LoggingBehavior(ILogger<LoggingBehavior<TRequest, TResponse>> logger) => _logger = logger;
|
||||
private readonly ILogger<LoggingBehavior<TRequest, TResponse>> _logger = logger;
|
||||
|
||||
public async Task<TResponse> Handle(
|
||||
TRequest request,
|
||||
|
||||
@@ -4,9 +4,7 @@ using MediatR;
|
||||
|
||||
namespace Shop.Application.Customer.Commands;
|
||||
|
||||
public class DeleteCustomerCommand : IRequest<Result>
|
||||
public class DeleteCustomerCommand(Guid id) : IRequest<Result>
|
||||
{
|
||||
public DeleteCustomerCommand(Guid id) => Id = id;
|
||||
|
||||
public Guid Id { get; }
|
||||
public Guid Id { get; } = id;
|
||||
}
|
||||
@@ -13,21 +13,14 @@ using Shop.Domain.ValueObjects;
|
||||
|
||||
namespace Shop.Application.Customer.Handlers;
|
||||
|
||||
public class CreateCustomerCommandHandler : IRequestHandler<CreateCustomerCommand, Result<CreatedCustomerResponse>>
|
||||
public class CreateCustomerCommandHandler(
|
||||
IValidator<CreateCustomerCommand> validator,
|
||||
ICustomerWriteOnlyRepository repository,
|
||||
IUnitOfWork unitOfWork) : IRequestHandler<CreateCustomerCommand, Result<CreatedCustomerResponse>>
|
||||
{
|
||||
private readonly ICustomerWriteOnlyRepository _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IValidator<CreateCustomerCommand> _validator;
|
||||
|
||||
public CreateCustomerCommandHandler(
|
||||
IValidator<CreateCustomerCommand> validator,
|
||||
ICustomerWriteOnlyRepository repository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_validator = validator;
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
private readonly ICustomerWriteOnlyRepository _repository = repository;
|
||||
private readonly IUnitOfWork _unitOfWork = unitOfWork;
|
||||
private readonly IValidator<CreateCustomerCommand> _validator = validator;
|
||||
|
||||
public async Task<Result<CreatedCustomerResponse>> Handle(
|
||||
CreateCustomerCommand request,
|
||||
|
||||
@@ -10,21 +10,14 @@ using Shop.Domain.Entities.CustomerAggregate;
|
||||
|
||||
namespace Shop.Application.Customer.Handlers;
|
||||
|
||||
public class DeleteCustomerCommandHandler : IRequestHandler<DeleteCustomerCommand, Result>
|
||||
public class DeleteCustomerCommandHandler(
|
||||
IValidator<DeleteCustomerCommand> validator,
|
||||
ICustomerWriteOnlyRepository repository,
|
||||
IUnitOfWork unitOfWork) : IRequestHandler<DeleteCustomerCommand, Result>
|
||||
{
|
||||
private readonly ICustomerWriteOnlyRepository _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IValidator<DeleteCustomerCommand> _validator;
|
||||
|
||||
public DeleteCustomerCommandHandler(
|
||||
IValidator<DeleteCustomerCommand> validator,
|
||||
ICustomerWriteOnlyRepository repository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_validator = validator;
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
private readonly ICustomerWriteOnlyRepository _repository = repository;
|
||||
private readonly IUnitOfWork _unitOfWork = unitOfWork;
|
||||
private readonly IValidator<DeleteCustomerCommand> _validator = validator;
|
||||
|
||||
public async Task<Result> Handle(DeleteCustomerCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
@@ -12,21 +12,14 @@ using Shop.Domain.ValueObjects;
|
||||
|
||||
namespace Shop.Application.Customer.Handlers;
|
||||
|
||||
public class UpdateCustomerCommandHandler : IRequestHandler<UpdateCustomerCommand, Result>
|
||||
public class UpdateCustomerCommandHandler(
|
||||
IValidator<UpdateCustomerCommand> validator,
|
||||
ICustomerWriteOnlyRepository repository,
|
||||
IUnitOfWork unitOfWork) : IRequestHandler<UpdateCustomerCommand, Result>
|
||||
{
|
||||
private readonly ICustomerWriteOnlyRepository _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IValidator<UpdateCustomerCommand> _validator;
|
||||
|
||||
public UpdateCustomerCommandHandler(
|
||||
IValidator<UpdateCustomerCommand> validator,
|
||||
ICustomerWriteOnlyRepository repository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_validator = validator;
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
private readonly ICustomerWriteOnlyRepository _repository = repository;
|
||||
private readonly IUnitOfWork _unitOfWork = unitOfWork;
|
||||
private readonly IValidator<UpdateCustomerCommand> _validator = validator;
|
||||
|
||||
public async Task<Result> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
@@ -3,9 +3,7 @@ using Shop.Core.SharedKernel;
|
||||
|
||||
namespace Shop.Application.Customer.Responses;
|
||||
|
||||
public class CreatedCustomerResponse : IResponse
|
||||
public class CreatedCustomerResponse(Guid id) : IResponse
|
||||
{
|
||||
public CreatedCustomerResponse(Guid id) => Id = id;
|
||||
|
||||
public Guid Id { get; }
|
||||
public Guid Id { get; } = id;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Shop.Core.SharedKernel;
|
||||
/// </summary>
|
||||
public abstract class BaseEntity : IEntity<Guid>
|
||||
{
|
||||
private readonly List<BaseEvent> _domainEvents = new();
|
||||
private readonly List<BaseEvent> _domainEvents = [];
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BaseEntity"/> class.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -2,15 +2,12 @@ using System;
|
||||
|
||||
namespace Shop.Domain.Entities.CustomerAggregate.Events;
|
||||
|
||||
public class CustomerCreatedEvent : CustomerBaseEvent
|
||||
public class CustomerCreatedEvent(
|
||||
Guid id,
|
||||
string firstName,
|
||||
string lastName,
|
||||
EGender gender,
|
||||
string email,
|
||||
DateTime dateOfBirth) : CustomerBaseEvent(id, firstName, lastName, gender, email, dateOfBirth)
|
||||
{
|
||||
public CustomerCreatedEvent(
|
||||
Guid id,
|
||||
string firstName,
|
||||
string lastName,
|
||||
EGender gender,
|
||||
string email,
|
||||
DateTime dateOfBirth) : base(id, firstName, lastName, gender, email, dateOfBirth)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,12 @@ using System;
|
||||
|
||||
namespace Shop.Domain.Entities.CustomerAggregate.Events;
|
||||
|
||||
public class CustomerDeletedEvent : CustomerBaseEvent
|
||||
public class CustomerDeletedEvent(
|
||||
Guid id,
|
||||
string firstName,
|
||||
string lastName,
|
||||
EGender gender,
|
||||
string email,
|
||||
DateTime dateOfBirth) : CustomerBaseEvent(id, firstName, lastName, gender, email, dateOfBirth)
|
||||
{
|
||||
public CustomerDeletedEvent(
|
||||
Guid id,
|
||||
string firstName,
|
||||
string lastName,
|
||||
EGender gender,
|
||||
string email,
|
||||
DateTime dateOfBirth) : base(id, firstName, lastName, gender, email, dateOfBirth)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,12 @@ using System;
|
||||
|
||||
namespace Shop.Domain.Entities.CustomerAggregate.Events;
|
||||
|
||||
public class CustomerUpdatedEvent : CustomerBaseEvent
|
||||
public class CustomerUpdatedEvent(
|
||||
Guid id,
|
||||
string firstName,
|
||||
string lastName,
|
||||
EGender gender,
|
||||
string email,
|
||||
DateTime dateOfBirth) : CustomerBaseEvent(id, firstName, lastName, gender, email, dateOfBirth)
|
||||
{
|
||||
public CustomerUpdatedEvent(
|
||||
Guid id,
|
||||
string firstName,
|
||||
string lastName,
|
||||
EGender gender,
|
||||
string email,
|
||||
DateTime dateOfBirth) : base(id, firstName, lastName, gender, email, dateOfBirth)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,13 +4,8 @@ using Shop.Infrastructure.Data.Mappings;
|
||||
|
||||
namespace Shop.Infrastructure.Data.Context;
|
||||
|
||||
public class EventStoreDbContext : BaseDbContext<EventStoreDbContext>
|
||||
public class EventStoreDbContext(DbContextOptions<EventStoreDbContext> dbOptions) : BaseDbContext<EventStoreDbContext>(dbOptions)
|
||||
{
|
||||
public EventStoreDbContext(DbContextOptions<EventStoreDbContext> dbOptions)
|
||||
: base(dbOptions)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<EventStore> EventStores => Set<EventStore>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
|
||||
@@ -6,18 +6,12 @@ using Shop.Infrastructure.Data.Mappings;
|
||||
|
||||
namespace Shop.Infrastructure.Data.Context;
|
||||
|
||||
public class WriteDbContext : BaseDbContext<WriteDbContext>
|
||||
public class WriteDbContext(DbContextOptions<WriteDbContext> dbOptions) : BaseDbContext<WriteDbContext>(dbOptions)
|
||||
{
|
||||
private static readonly byte[] EncryptionKey = { 189, 3, 80, 118, 242, 164, 9, 197, 106, 166, 122, 118, 161, 212, 106, 26, 171, 18, 178, 98, 86, 102, 196, 6, 78, 249, 4, 164, 66, 154, 218, 126 };
|
||||
private static readonly byte[] EncryptionVector = { 163, 225, 4, 33, 227, 178, 113, 128, 174, 23, 9, 144, 213, 158, 134, 48 };
|
||||
private static readonly byte[] EncryptionKey = [189, 3, 80, 118, 242, 164, 9, 197, 106, 166, 122, 118, 161, 212, 106, 26, 171, 18, 178, 98, 86, 102, 196, 6, 78, 249, 4, 164, 66, 154, 218, 126];
|
||||
private static readonly byte[] EncryptionVector = [163, 225, 4, 33, 227, 178, 113, 128, 174, 23, 9, 144, 213, 158, 134, 48];
|
||||
|
||||
private readonly IEncryptionProvider _encryptionProvider;
|
||||
|
||||
public WriteDbContext(DbContextOptions<WriteDbContext> dbOptions)
|
||||
: base(dbOptions)
|
||||
{
|
||||
_encryptionProvider = new AesProvider(EncryptionKey, EncryptionVector);
|
||||
}
|
||||
private readonly IEncryptionProvider _encryptionProvider = new AesProvider(EncryptionKey, EncryptionVector);
|
||||
|
||||
public DbSet<Customer> Customers => Set<Customer>();
|
||||
|
||||
|
||||
@@ -8,12 +8,8 @@ using Shop.Infrastructure.Data.Repositories.Common;
|
||||
|
||||
namespace Shop.Infrastructure.Data.Repositories;
|
||||
|
||||
internal class CustomerWriteOnlyRepository : BaseWriteOnlyRepository<Customer, Guid>, ICustomerWriteOnlyRepository
|
||||
internal class CustomerWriteOnlyRepository(WriteDbContext context) : BaseWriteOnlyRepository<Customer, Guid>(context), ICustomerWriteOnlyRepository
|
||||
{
|
||||
public CustomerWriteOnlyRepository(WriteDbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<bool> ExistsByEmailAsync(Email email) =>
|
||||
await Context.Customers
|
||||
.AsNoTracking()
|
||||
|
||||
@@ -6,12 +6,9 @@ using Shop.Infrastructure.Data.Context;
|
||||
|
||||
namespace Shop.Infrastructure.Data.Repositories;
|
||||
|
||||
internal sealed class EventStoreRepository : IEventStoreRepository
|
||||
internal sealed class EventStoreRepository(EventStoreDbContext context) : IEventStoreRepository
|
||||
{
|
||||
private readonly EventStoreDbContext _context;
|
||||
|
||||
public EventStoreRepository(EventStoreDbContext context) =>
|
||||
_context = context;
|
||||
private readonly EventStoreDbContext _context = context;
|
||||
|
||||
public async Task StoreAsync(IEnumerable<EventStore> eventStores)
|
||||
{
|
||||
|
||||
@@ -12,24 +12,16 @@ using Shop.Infrastructure.Data.Context;
|
||||
|
||||
namespace Shop.Infrastructure.Data;
|
||||
|
||||
internal sealed class UnitOfWork : IUnitOfWork
|
||||
internal sealed class UnitOfWork(
|
||||
WriteDbContext writeDbContext,
|
||||
IEventStoreRepository eventStoreRepository,
|
||||
IMediator mediator,
|
||||
ILogger<UnitOfWork> logger) : IUnitOfWork
|
||||
{
|
||||
private readonly IEventStoreRepository _eventStoreRepository;
|
||||
private readonly ILogger<UnitOfWork> _logger;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly WriteDbContext _writeDbContext;
|
||||
|
||||
public UnitOfWork(
|
||||
WriteDbContext writeDbContext,
|
||||
IEventStoreRepository eventStoreRepository,
|
||||
IMediator mediator,
|
||||
ILogger<UnitOfWork> logger)
|
||||
{
|
||||
_writeDbContext = writeDbContext;
|
||||
_eventStoreRepository = eventStoreRepository;
|
||||
_mediator = mediator;
|
||||
_logger = logger;
|
||||
}
|
||||
private readonly IEventStoreRepository _eventStoreRepository = eventStoreRepository;
|
||||
private readonly ILogger<UnitOfWork> _logger = logger;
|
||||
private readonly IMediator _mediator = mediator;
|
||||
private readonly WriteDbContext _writeDbContext = writeDbContext;
|
||||
|
||||
/// <summary>
|
||||
/// Saves changes asynchronously.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -18,12 +18,9 @@ namespace Shop.PublicApi.Controllers.V1;
|
||||
[ApiController]
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/[controller]")]
|
||||
public class CustomersController : ControllerBase
|
||||
public class CustomersController(IMediator mediator) : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public CustomersController(IMediator mediator) =>
|
||||
_mediator = mediator;
|
||||
private readonly IMediator _mediator = mediator;
|
||||
|
||||
////////////////////////
|
||||
// POST: /api/customers
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0-bookworm-slim AS base
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
|
||||
@@ -7,7 +7,7 @@ ENV DOTNET_NOLOGO=1
|
||||
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
|
||||
ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0-bookworm-slim AS build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS build
|
||||
WORKDIR /src
|
||||
COPY ["Directory.Packages.props", "."]
|
||||
COPY ["Directory.Build.props", "."]
|
||||
@@ -24,7 +24,7 @@ WORKDIR "/src/src/Shop.PublicApi"
|
||||
RUN dotnet build "Shop.PublicApi.csproj" --configuration Release --no-restore --nologo --output /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "Shop.PublicApi.csproj" --configuration Release --no-restore --nologo --self-contained true --output /app/publish
|
||||
RUN dotnet publish "Shop.PublicApi.csproj" --configuration Release --no-restore --nologo --output /app/publish
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
|
||||
@@ -24,8 +24,8 @@ internal static class ServicesCollectionExtensions
|
||||
private const string DbMigrationAssemblyName = "Shop.PublicApi";
|
||||
private const string RedisInstanceName = "master";
|
||||
|
||||
private static readonly string[] DbRelationalTags = { "database", "ef-core", "sql-server", "relational" };
|
||||
private static readonly string[] DbNoSqlTags = { "database", "mongodb", "no-sql" };
|
||||
private static readonly string[] DbRelationalTags = ["database", "ef-core", "sql-server", "relational"];
|
||||
private static readonly string[] DbNoSqlTags = ["database", "mongodb", "no-sql"];
|
||||
|
||||
public static void AddSwagger(this IServiceCollection services)
|
||||
{
|
||||
|
||||
@@ -5,12 +5,10 @@ using Shop.Core.SharedKernel.Correlation;
|
||||
|
||||
namespace Shop.PublicApi.Middlewares;
|
||||
|
||||
public class CorrelationIdMiddleware
|
||||
public class CorrelationIdMiddleware(RequestDelegate next)
|
||||
{
|
||||
private const string CorrelationIdHeaderKey = "X-Correlation-Id";
|
||||
private readonly RequestDelegate _next;
|
||||
|
||||
public CorrelationIdMiddleware(RequestDelegate next) => _next = next;
|
||||
private readonly RequestDelegate _next = next;
|
||||
|
||||
public async Task Invoke(HttpContext context, ICorrelationIdGenerator correlationIdGenerator)
|
||||
{
|
||||
@@ -34,7 +32,7 @@ public class CorrelationIdMiddleware
|
||||
{
|
||||
context.Response.OnStarting(() =>
|
||||
{
|
||||
context.Response.Headers.Add(CorrelationIdHeaderKey, new[] { correlationId.ToString() });
|
||||
context.Response.Headers.Append(CorrelationIdHeaderKey, new[] { correlationId.ToString() });
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,24 +9,17 @@ using Shop.PublicApi.Models;
|
||||
|
||||
namespace Shop.PublicApi.Middlewares;
|
||||
|
||||
public class ErrorHandlingMiddleware
|
||||
public class ErrorHandlingMiddleware(
|
||||
RequestDelegate next,
|
||||
ILogger<ErrorHandlingMiddleware> logger,
|
||||
IHostEnvironment environment)
|
||||
{
|
||||
private const string ErrorMessage = "An internal error occurred while processing your request.";
|
||||
private static readonly string ApiResponseJson = ApiResponse.InternalServerError(ErrorMessage).ToJson();
|
||||
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly ILogger<ErrorHandlingMiddleware> _logger;
|
||||
private readonly IHostEnvironment _environment;
|
||||
|
||||
public ErrorHandlingMiddleware(
|
||||
RequestDelegate next,
|
||||
ILogger<ErrorHandlingMiddleware> logger,
|
||||
IHostEnvironment environment)
|
||||
{
|
||||
_next = next;
|
||||
_logger = logger;
|
||||
_environment = environment;
|
||||
}
|
||||
private readonly RequestDelegate _next = next;
|
||||
private readonly ILogger<ErrorHandlingMiddleware> _logger = logger;
|
||||
private readonly IHostEnvironment _environment = environment;
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
|
||||
@@ -2,12 +2,10 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace Shop.PublicApi.Models;
|
||||
|
||||
public sealed class ApiErrorResponse
|
||||
[method: JsonConstructor]
|
||||
public sealed class ApiErrorResponse(string message)
|
||||
{
|
||||
[JsonConstructor]
|
||||
public ApiErrorResponse(string message) => Message = message;
|
||||
|
||||
public string Message { get; }
|
||||
public string Message { get; } = message;
|
||||
|
||||
public override string ToString() => Message;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public class ApiResponse
|
||||
public static ApiResponse InternalServerError(IEnumerable<ApiErrorResponse> errors) =>
|
||||
new() { Success = false, StatusCode = StatusCodes.Status500InternalServerError, Errors = errors };
|
||||
|
||||
private static IEnumerable<ApiErrorResponse> CreateErrors(string errorMessage) =>
|
||||
private static ApiErrorResponse[] CreateErrors(string errorMessage) =>
|
||||
new[] { new ApiErrorResponse(errorMessage) };
|
||||
|
||||
public override string ToString() =>
|
||||
|
||||
@@ -112,7 +112,6 @@ app.UseErrorHandling();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseResponseCompression();
|
||||
app.UseHttpLogging();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseMiniProfiler();
|
||||
app.UseCorrelationId();
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<DockerTargetOS>Linux</DockerTargetOS>
|
||||
<UserSecretsId>7d8d0af0-7540-48a6-b160-d34c988a1ad6</UserSecretsId>
|
||||
<DockerTargetOS>Linux</DockerTargetOS>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||
<DockerfileContext>..\..</DockerfileContext>
|
||||
<DockerComposeProjectPath>..\..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.AspNetCore": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information",
|
||||
"Microsoft.EntityFrameworkCore": "Information",
|
||||
"Microsoft.AspNetCore.DataProtection": "Information"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.AspNetCore": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information",
|
||||
"Microsoft.EntityFrameworkCore": "Information",
|
||||
"Microsoft.AspNetCore.DataProtection": "Information"
|
||||
|
||||
@@ -10,17 +10,11 @@ using Shop.Query.QueriesModel;
|
||||
|
||||
namespace Shop.Query.Application.Customer.Handlers;
|
||||
|
||||
public class GetAllCustomerQueryHandler : IRequestHandler<GetAllCustomerQuery, Result<IEnumerable<CustomerQueryModel>>>
|
||||
public class GetAllCustomerQueryHandler(ICustomerReadOnlyRepository repository, ICacheService cacheService) : IRequestHandler<GetAllCustomerQuery, Result<IEnumerable<CustomerQueryModel>>>
|
||||
{
|
||||
private const string CacheKey = nameof(GetAllCustomerQuery);
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly ICustomerReadOnlyRepository _readOnlyRepository;
|
||||
|
||||
public GetAllCustomerQueryHandler(ICustomerReadOnlyRepository repository, ICacheService cacheService)
|
||||
{
|
||||
_readOnlyRepository = repository;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
private readonly ICacheService _cacheService = cacheService;
|
||||
private readonly ICustomerReadOnlyRepository _readOnlyRepository = repository;
|
||||
|
||||
public async Task<Result<IEnumerable<CustomerQueryModel>>> Handle(
|
||||
GetAllCustomerQuery request,
|
||||
|
||||
@@ -11,21 +11,14 @@ using Shop.Query.QueriesModel;
|
||||
|
||||
namespace Shop.Query.Application.Customer.Handlers;
|
||||
|
||||
public class GetCustomerByIdQueryHandler : IRequestHandler<GetCustomerByIdQuery, Result<CustomerQueryModel>>
|
||||
public class GetCustomerByIdQueryHandler(
|
||||
IValidator<GetCustomerByIdQuery> validator,
|
||||
ICustomerReadOnlyRepository repository,
|
||||
ICacheService cacheService) : IRequestHandler<GetCustomerByIdQuery, Result<CustomerQueryModel>>
|
||||
{
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly ICustomerReadOnlyRepository _repository;
|
||||
private readonly IValidator<GetCustomerByIdQuery> _validator;
|
||||
|
||||
public GetCustomerByIdQueryHandler(
|
||||
IValidator<GetCustomerByIdQuery> validator,
|
||||
ICustomerReadOnlyRepository repository,
|
||||
ICacheService cacheService)
|
||||
{
|
||||
_validator = validator;
|
||||
_repository = repository;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
private readonly ICacheService _cacheService = cacheService;
|
||||
private readonly ICustomerReadOnlyRepository _repository = repository;
|
||||
private readonly IValidator<GetCustomerByIdQuery> _validator = validator;
|
||||
|
||||
public async Task<Result<CustomerQueryModel>> Handle(
|
||||
GetCustomerByIdQuery request,
|
||||
|
||||
@@ -5,9 +5,7 @@ using Shop.Query.QueriesModel;
|
||||
|
||||
namespace Shop.Query.Application.Customer.Queries;
|
||||
|
||||
public class GetCustomerByIdQuery : IRequest<Result<CustomerQueryModel>>
|
||||
public class GetCustomerByIdQuery(Guid id) : IRequest<Result<CustomerQueryModel>>
|
||||
{
|
||||
public GetCustomerByIdQuery(Guid id) => Id = id;
|
||||
|
||||
public Guid Id { get; }
|
||||
public Guid Id { get; } = id;
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public sealed class NoSqlDbContext : IReadDbContext, ISynchronizeDb
|
||||
await collection.Indexes.CreateOneAsync(indexModel);
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetCollectionNamesFromAssembly() =>
|
||||
private static List<string> GetCollectionNamesFromAssembly() =>
|
||||
Assembly
|
||||
.GetExecutingAssembly()
|
||||
.GetAllTypesOf<IQueryModel>()
|
||||
|
||||
@@ -8,10 +8,8 @@ using Shop.Query.QueriesModel;
|
||||
|
||||
namespace Shop.Query.Data.Repositories;
|
||||
|
||||
internal class CustomerReadOnlyRepository : BaseReadOnlyRepository<CustomerQueryModel, Guid>, ICustomerReadOnlyRepository
|
||||
internal class CustomerReadOnlyRepository(IReadDbContext readDbContext) : BaseReadOnlyRepository<CustomerQueryModel, Guid>(readDbContext), ICustomerReadOnlyRepository
|
||||
{
|
||||
public CustomerReadOnlyRepository(IReadDbContext readDbContext) : base(readDbContext) { }
|
||||
|
||||
public async Task<IEnumerable<CustomerQueryModel>> GetAllAsync() =>
|
||||
await Collection
|
||||
.Find(Builders<CustomerQueryModel>.Filter.Empty)
|
||||
|
||||
@@ -12,27 +12,19 @@ using Shop.Query.QueriesModel;
|
||||
|
||||
namespace Shop.Query.EventHandlers;
|
||||
|
||||
public class CustomerEventHandler :
|
||||
public class CustomerEventHandler(
|
||||
IMapper mapper,
|
||||
ISynchronizeDb synchronizeDb,
|
||||
ICacheService cacheService,
|
||||
ILogger<CustomerEventHandler> logger) :
|
||||
INotificationHandler<CustomerCreatedEvent>,
|
||||
INotificationHandler<CustomerUpdatedEvent>,
|
||||
INotificationHandler<CustomerDeletedEvent>
|
||||
{
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly ILogger<CustomerEventHandler> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly ISynchronizeDb _synchronizeDb;
|
||||
|
||||
public CustomerEventHandler(
|
||||
IMapper mapper,
|
||||
ISynchronizeDb synchronizeDb,
|
||||
ICacheService cacheService,
|
||||
ILogger<CustomerEventHandler> logger)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_synchronizeDb = synchronizeDb;
|
||||
_cacheService = cacheService;
|
||||
_logger = logger;
|
||||
}
|
||||
private readonly ICacheService _cacheService = cacheService;
|
||||
private readonly ILogger<CustomerEventHandler> _logger = logger;
|
||||
private readonly IMapper _mapper = mapper;
|
||||
private readonly ISynchronizeDb _synchronizeDb = synchronizeDb;
|
||||
|
||||
public async Task Handle(CustomerCreatedEvent notification, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
+2
-4
@@ -20,13 +20,11 @@ using Xunit.Categories;
|
||||
namespace Shop.UnitTests.Application.Customer.Handlers;
|
||||
|
||||
[UnitTest]
|
||||
public class CreateCustomerCommandHandlerTests : IClassFixture<EfSqliteFixture>
|
||||
public class CreateCustomerCommandHandlerTests(EfSqliteFixture fixture) : IClassFixture<EfSqliteFixture>
|
||||
{
|
||||
private readonly EfSqliteFixture _fixture;
|
||||
private readonly EfSqliteFixture _fixture = fixture;
|
||||
private readonly CreateCustomerCommandValidator _validator = new();
|
||||
|
||||
public CreateCustomerCommandHandlerTests(EfSqliteFixture fixture) => _fixture = fixture;
|
||||
|
||||
[Fact]
|
||||
public async Task Add_ValidCommand_ShouldReturnsSuccessResult()
|
||||
{
|
||||
|
||||
+2
-4
@@ -20,13 +20,11 @@ using Xunit.Categories;
|
||||
namespace Shop.UnitTests.Application.Customer.Handlers;
|
||||
|
||||
[UnitTest]
|
||||
public class DeleteCustomerCommandHandlerTests : IClassFixture<EfSqliteFixture>
|
||||
public class DeleteCustomerCommandHandlerTests(EfSqliteFixture fixture) : IClassFixture<EfSqliteFixture>
|
||||
{
|
||||
private readonly EfSqliteFixture _fixture;
|
||||
private readonly EfSqliteFixture _fixture = fixture;
|
||||
private readonly DeleteCustomerCommandValidator _validator = new();
|
||||
|
||||
public DeleteCustomerCommandHandlerTests(EfSqliteFixture fixture) => _fixture = fixture;
|
||||
|
||||
[Fact]
|
||||
public async Task Delete_ValidCustomerId_ShouldReturnsSuccessResult()
|
||||
{
|
||||
|
||||
+2
-4
@@ -19,13 +19,11 @@ using Xunit.Categories;
|
||||
namespace Shop.UnitTests.Application.Customer.Handlers;
|
||||
|
||||
[UnitTest]
|
||||
public class UpdateCustomerCommandHandlerTest : IClassFixture<EfSqliteFixture>
|
||||
public class UpdateCustomerCommandHandlerTest(EfSqliteFixture fixture) : IClassFixture<EfSqliteFixture>
|
||||
{
|
||||
private readonly EfSqliteFixture _fixture;
|
||||
private readonly EfSqliteFixture _fixture = fixture;
|
||||
private readonly UpdateCustomerCommandValidator _validator = new();
|
||||
|
||||
public UpdateCustomerCommandHandlerTest(EfSqliteFixture fixture) => _fixture = fixture;
|
||||
|
||||
[Fact]
|
||||
public async Task Update_ValidCommand_ShouldReturnsSuccessResult()
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<SonarQubeTestProject>True</SonarQubeTestProject>
|
||||
|
||||
Reference in New Issue
Block a user