hn-dotnet/Application/AddLink/AddLinkCommandHandler.cs

30 lines
600 B
C#

using System;
using System.Threading;
using System.Threading.Tasks;
using HN.Domain;
using MediatR;
namespace HN.Application
{
public class AddLinkCommandHandler : IRequestHandler<AddLinkCommand, Guid>
{
private readonly ILinkRepository _repository;
public AddLinkCommandHandler(ILinkRepository repository)
{
this._repository = repository;
}
public async Task<Guid> Handle(AddLinkCommand request, CancellationToken cancellationToken)
{
var link = Link.FromUrl(request.Url);
await this._repository.AddAsync(link);
return link.Id;
}
}
}