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

33 lines
1.1 KiB
C#

using Jambo.Producer.Application.Commands.Blogs;
using Jambo.Domain.Model.Blogs;
using MediatR;
using System;
using System.Threading.Tasks;
using Jambo.Domain.ServiceBus;
namespace Jambo.Producer.Application.CommandHandlers.Blogs
{
public class DisableBlogCommandHandler : IAsyncRequestHandler<DisableBlogCommand>
{
private readonly IPublisher bus;
private readonly IBlogReadOnlyRepository blogReadOnlyRepository;
public DisableBlogCommandHandler(
IPublisher bus,
IBlogReadOnlyRepository blogReadOnlyRepository)
{
this.bus = bus ?? throw new ArgumentNullException(nameof(bus));
this.blogReadOnlyRepository = blogReadOnlyRepository ??
throw new ArgumentNullException(nameof(blogReadOnlyRepository));
}
public async Task Handle(DisableBlogCommand command)
{
Blog blog = await blogReadOnlyRepository.GetBlog(command.Id);
blog.Disable();
await bus.Publish(blog.GetEvents(), command.Header);
}
}
}