Introduced a generic CreateCommandHandler class implementing MediatR's IRequestHandler to handle create commands. The handler uses a generic IRepository to perform asynchronous entity creation and supports dependency injection for repository access.
36 lines
965 B
C#
36 lines
965 B
C#
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using MediatR;
|
|
|
|
namespace EnvelopeGenerator.Application.Common.Commands;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <typeparam name="TCommand"></typeparam>
|
|
/// <typeparam name="TEntity"></typeparam>
|
|
public class CreateCommandHandler<TCommand, TEntity> : IRequestHandler<TCommand>
|
|
where TCommand : class, IRequest
|
|
where TEntity : class
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
protected readonly IRepository<TEntity> Repository;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="repository"></param>
|
|
public CreateCommandHandler(IRepository<TEntity> repository)
|
|
{
|
|
Repository = repository;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
public Task Handle(TCommand request, CancellationToken cancel) => Repository.CreateAsync(request, cancel);
|
|
} |