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