Files
event-sourcing-jambo/source/Producer/Jambo.Producer.Application/CommandHandlers/Posts/DisablePostCommandHandler.cs
Ivan Paulovich fc74b10766 Spliting projects
2017-12-21 15:59:03 -02:00

37 lines
1.2 KiB
C#

using Jambo.Producer.Application.Commands;
using Jambo.Producer.Application.Commands.Blogs;
using Jambo.Producer.Application.Commands.Posts;
using Jambo.Domain.Model.Blogs;
using Jambo.Domain.Model.Posts;
using MediatR;
using System;
using System.Threading.Tasks;
using Jambo.Domain.ServiceBus;
namespace Jambo.Producer.Application.CommandHandlers.Posts
{
public class DisablePostCommandHandler : IAsyncRequestHandler<DisablePostCommand>
{
private readonly IPublisher bus;
private readonly IPostReadOnlyRepository postReadOnlyRepository;
public DisablePostCommandHandler(
IPublisher bus,
IPostReadOnlyRepository postReadOnlyRepository)
{
this.bus = bus ??
throw new ArgumentNullException(nameof(bus));
this.postReadOnlyRepository = postReadOnlyRepository ??
throw new ArgumentNullException(nameof(postReadOnlyRepository));
}
public async Task Handle(DisablePostCommand command)
{
Post post = await postReadOnlyRepository.GetPost(command.Id);
post.Disable();
await bus.Publish(post.GetEvents(), command.Header);
}
}
}