using System; using System.Threading; using System.Threading.Tasks; using HN.Domain; using MediatR; namespace HN.Application { public sealed class CommentLinkCommandHandler : IRequestHandler { private readonly ILinkRepository _linkRepository; private readonly ICommentRepository _commentRepository; public CommentLinkCommandHandler(ILinkRepository linkRepository, ICommentRepository commentRepository) { _linkRepository = linkRepository; _commentRepository = commentRepository; } public async Task Handle(CommentLinkCommand request, CancellationToken cancellationToken) { var link = await _linkRepository.GetByIdAsync(request.LinkId); var comment = link.AddComment(request.Content); await _commentRepository.AddAsync(comment); return comment.Id; } } }