Replaced direct service usage in CatalogsController with MediatR-based commands and queries for all CRUD operations. Added command/query and handler classes for Catalog operations. Updated dependency injection to register MediatR and removed ICatalogService. Improved code maintainability and testability by adopting CQRS architecture.
20 lines
540 B
C#
20 lines
540 B
C#
using DbFirst.Domain.Repositories;
|
|
using MediatR;
|
|
|
|
namespace DbFirst.Application.Catalogs.Commands;
|
|
|
|
public class DeleteCatalogHandler : IRequestHandler<DeleteCatalogCommand, bool>
|
|
{
|
|
private readonly ICatalogRepository _repository;
|
|
|
|
public DeleteCatalogHandler(ICatalogRepository repository)
|
|
{
|
|
_repository = repository;
|
|
}
|
|
|
|
public async Task<bool> Handle(DeleteCatalogCommand request, CancellationToken cancellationToken)
|
|
{
|
|
return await _repository.DeleteAsync(request.Id, cancellationToken);
|
|
}
|
|
}
|