Changed CreateCommandHandler to implement IRequestHandler<TCommand, TEntity> and updated method signatures to return the created entity. Adjusted generic constraints to require TCommand to implement IRequest<TEntity>.
36 lines
992 B
C#
36 lines
992 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, TEntity>
|
|
where TCommand : class, IRequest<TEntity>
|
|
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<TEntity> Handle(TCommand request, CancellationToken cancel) => Repository.CreateAsync(request, cancel);
|
|
} |