diff --git a/application/account-management/Application/Users/CreateUser.cs b/application/account-management/Application/Users/CreateUser.cs index 1c822209f..92216ac20 100644 --- a/application/account-management/Application/Users/CreateUser.cs +++ b/application/account-management/Application/Users/CreateUser.cs @@ -7,19 +7,12 @@ public sealed record CreateUserCommand(TenantId TenantId, string Email, UserRole : ICommand, IUserValidation, IRequest>; [UsedImplicitly] -public sealed class CreateUserHandler : IRequestHandler> +public sealed class CreateUserHandler(IUserRepository userRepository) : IRequestHandler> { - private readonly IUserRepository _userRepository; - - public CreateUserHandler(IUserRepository userRepository) - { - _userRepository = userRepository; - } - public async Task> Handle(CreateUserCommand command, CancellationToken cancellationToken) { var user = User.Create(command.TenantId, command.Email, command.UserRole); - await _userRepository.AddAsync(user, cancellationToken); + await userRepository.AddAsync(user, cancellationToken); return user.Id; } } diff --git a/application/account-management/Application/Users/DeleteUser.cs b/application/account-management/Application/Users/DeleteUser.cs index 14b29c55d..39ca4999b 100644 --- a/application/account-management/Application/Users/DeleteUser.cs +++ b/application/account-management/Application/Users/DeleteUser.cs @@ -5,21 +5,14 @@ namespace PlatformPlatform.AccountManagement.Application.Users; public sealed record DeleteUserCommand(UserId Id) : ICommand, IRequest; [UsedImplicitly] -public sealed class DeleteUserHandler : IRequestHandler +public sealed class DeleteUserHandler(IUserRepository userRepository) : IRequestHandler { - private readonly IUserRepository _userRepository; - - public DeleteUserHandler(IUserRepository userRepository) - { - _userRepository = userRepository; - } - public async Task Handle(DeleteUserCommand command, CancellationToken cancellationToken) { - var user = await _userRepository.GetByIdAsync(command.Id, cancellationToken); + var user = await userRepository.GetByIdAsync(command.Id, cancellationToken); if (user is null) return Result.NotFound($"User with id '{command.Id}' not found."); - _userRepository.Remove(user); + userRepository.Remove(user); return Result.Success(); } } \ No newline at end of file diff --git a/application/account-management/Application/Users/GetUser.cs b/application/account-management/Application/Users/GetUser.cs index 98382f943..604fff0f8 100644 --- a/application/account-management/Application/Users/GetUser.cs +++ b/application/account-management/Application/Users/GetUser.cs @@ -6,18 +6,11 @@ namespace PlatformPlatform.AccountManagement.Application.Users; public sealed record GetUserQuery(UserId Id) : IRequest>; [UsedImplicitly] -public sealed class GetUserHandler : IRequestHandler> +public sealed class GetUserHandler(IUserRepository userRepository) : IRequestHandler> { - private readonly IUserRepository _userRepository; - - public GetUserHandler(IUserRepository userRepository) - { - _userRepository = userRepository; - } - public async Task> Handle(GetUserQuery request, CancellationToken cancellationToken) { - var user = await _userRepository.GetByIdAsync(request.Id, cancellationToken); + var user = await userRepository.GetByIdAsync(request.Id, cancellationToken); return user?.Adapt() ?? Result.NotFound($"User with id '{request.Id}' not found."); } diff --git a/application/account-management/Application/Users/UpdateUser.cs b/application/account-management/Application/Users/UpdateUser.cs index b5d463149..c79bc4f3b 100644 --- a/application/account-management/Application/Users/UpdateUser.cs +++ b/application/account-management/Application/Users/UpdateUser.cs @@ -13,22 +13,15 @@ public sealed record UpdateUserCommand : ICommand, IUserValidation, IRequest +public sealed class UpdateUserHandler(IUserRepository userRepository) : IRequestHandler { - private readonly IUserRepository _userRepository; - - public UpdateUserHandler(IUserRepository userRepository) - { - _userRepository = userRepository; - } - public async Task Handle(UpdateUserCommand command, CancellationToken cancellationToken) { - var user = await _userRepository.GetByIdAsync(command.Id, cancellationToken); + var user = await userRepository.GetByIdAsync(command.Id, cancellationToken); if (user is null) return Result.NotFound($"User with id '{command.Id}' not found."); user.Update(command.Email, command.UserRole); - _userRepository.Update(user); + userRepository.Update(user); return Result.Success(); } } diff --git a/application/shared-kernel/ApiCore/Middleware/GlobalExceptionHandlerMiddleware.cs b/application/shared-kernel/ApiCore/Middleware/GlobalExceptionHandlerMiddleware.cs index 5373fa183..00a87c1b2 100644 --- a/application/shared-kernel/ApiCore/Middleware/GlobalExceptionHandlerMiddleware.cs +++ b/application/shared-kernel/ApiCore/Middleware/GlobalExceptionHandlerMiddleware.cs @@ -7,17 +7,11 @@ namespace PlatformPlatform.SharedKernel.ApiCore.Middleware; -public sealed class GlobalExceptionHandlerMiddleware : IMiddleware +public sealed class GlobalExceptionHandlerMiddleware(ILogger logger, + IOptions jsonOptions) : IMiddleware { - private readonly JsonSerializerOptions _jsonSerializerOptions; - private readonly ILogger _logger; - - public GlobalExceptionHandlerMiddleware(ILogger logger, - IOptions jsonOptions) - { - _logger = logger; - _jsonSerializerOptions = jsonOptions.Value.SerializerOptions; - } + private readonly JsonSerializerOptions _jsonSerializerOptions = jsonOptions.Value.SerializerOptions; + private readonly ILogger _logger = logger; public async Task InvokeAsync(HttpContext context, RequestDelegate next) { diff --git a/application/shared-kernel/ApiCore/Middleware/ModelBindingExceptionHandlerMiddleware.cs b/application/shared-kernel/ApiCore/Middleware/ModelBindingExceptionHandlerMiddleware.cs index b53a930af..b3717ed93 100644 --- a/application/shared-kernel/ApiCore/Middleware/ModelBindingExceptionHandlerMiddleware.cs +++ b/application/shared-kernel/ApiCore/Middleware/ModelBindingExceptionHandlerMiddleware.cs @@ -7,14 +7,9 @@ namespace PlatformPlatform.SharedKernel.ApiCore.Middleware; -public sealed class ModelBindingExceptionHandlerMiddleware : IMiddleware +public sealed class ModelBindingExceptionHandlerMiddleware(IOptions jsonOptions) : IMiddleware { - private readonly JsonSerializerOptions _jsonSerializerOptions; - - public ModelBindingExceptionHandlerMiddleware(IOptions jsonOptions) - { - _jsonSerializerOptions = jsonOptions.Value.SerializerOptions; - } + private readonly JsonSerializerOptions _jsonSerializerOptions = jsonOptions.Value.SerializerOptions; public async Task InvokeAsync(HttpContext context, RequestDelegate next) { diff --git a/application/shared-kernel/InfrastructureCore/Persistence/DomainEventCollector.cs b/application/shared-kernel/InfrastructureCore/Persistence/DomainEventCollector.cs index aba5d3cb6..4667af562 100644 --- a/application/shared-kernel/InfrastructureCore/Persistence/DomainEventCollector.cs +++ b/application/shared-kernel/InfrastructureCore/Persistence/DomainEventCollector.cs @@ -4,18 +4,11 @@ namespace PlatformPlatform.SharedKernel.InfrastructureCore.Persistence; -public sealed class DomainEventCollector : IDomainEventCollector +public sealed class DomainEventCollector(DbContext dbContext) : IDomainEventCollector { - private readonly DbContext _dbContext; - - public DomainEventCollector(DbContext dbContext) - { - _dbContext = dbContext; - } - public IEnumerable GetAggregatesWithDomainEvents() { - return _dbContext.ChangeTracker + return dbContext.ChangeTracker .Entries() .Where(e => e.Entity.DomainEvents.Any()) .Select(e => e.Entity); diff --git a/application/shared-kernel/Tests/TestEntities/TestAggregate.cs b/application/shared-kernel/Tests/TestEntities/TestAggregate.cs index 34c9ca9dc..379748357 100644 --- a/application/shared-kernel/Tests/TestEntities/TestAggregate.cs +++ b/application/shared-kernel/Tests/TestEntities/TestAggregate.cs @@ -3,14 +3,9 @@ namespace PlatformPlatform.SharedKernel.Tests.TestEntities; -public sealed class TestAggregate : AggregateRoot +public sealed class TestAggregate(string name) : AggregateRoot(IdGenerator.NewId()) { - private TestAggregate(string name) : base(IdGenerator.NewId()) - { - Name = name; - } - - public string Name { get; set; } + public string Name { get; set; } = name; public static TestAggregate Create(string name) { diff --git a/application/shared-kernel/Tests/TestEntities/TestAggregateRepository.cs b/application/shared-kernel/Tests/TestEntities/TestAggregateRepository.cs index e18085aed..c46acc031 100644 --- a/application/shared-kernel/Tests/TestEntities/TestAggregateRepository.cs +++ b/application/shared-kernel/Tests/TestEntities/TestAggregateRepository.cs @@ -2,9 +2,5 @@ namespace PlatformPlatform.SharedKernel.Tests.TestEntities; -public class TestAggregateRepository : RepositoryBase, ITestAggregateRepository -{ - public TestAggregateRepository(TestDbContext testDbContext) : base(testDbContext) - { - } -} \ No newline at end of file +public class TestAggregateRepository(TestDbContext testDbContext) + : RepositoryBase(testDbContext), ITestAggregateRepository; \ No newline at end of file diff --git a/application/shared-kernel/Tests/TestEntities/TestDbContext.cs b/application/shared-kernel/Tests/TestEntities/TestDbContext.cs index d47e1fc77..a8018c396 100644 --- a/application/shared-kernel/Tests/TestEntities/TestDbContext.cs +++ b/application/shared-kernel/Tests/TestEntities/TestDbContext.cs @@ -3,12 +3,8 @@ namespace PlatformPlatform.SharedKernel.Tests.TestEntities; -public class TestDbContext : SharedKernelDbContext +public class TestDbContext(DbContextOptions options) : SharedKernelDbContext(options) { - public TestDbContext(DbContextOptions options) : base(options) - { - } - public DbSet TestAggregates => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder)