Files
event-sourcing-jambo/source/Jambo.Application/CommandHandlers/Blogs/EnableBlogCommandHandler.cs
Ivan Paulovich 2eddbb65e2 ok
2017-08-22 18:30:10 -03:00

37 lines
1.2 KiB
C#

using MediatR;
using System;
using System.Threading.Tasks;
using Jambo.Application.Commands;
using Jambo.Domain.ServiceBus;
using Jambo.Domain.Aggregates.Blogs;
using Jambo.Application.Commands.Blogs;
using Jambo.Domain.Aggregates.Posts;
using Jambo.Application.Commands.Posts;
namespace Jambo.Application.CommandHandlers.Blogs
{
public class EnableBlogCommandHandler : IAsyncRequestHandler<HidePostCommand>
{
private readonly IServiceBus _serviceBus;
private readonly IBlogReadOnlyRepository _blogReadOnlyRepository;
public EnableBlogCommandHandler(
IServiceBus serviceBus,
IBlogReadOnlyRepository blogReadOnlyRepository)
{
_serviceBus = serviceBus ??
throw new ArgumentNullException(nameof(serviceBus));
_blogReadOnlyRepository = blogReadOnlyRepository ??
throw new ArgumentNullException(nameof(blogReadOnlyRepository));
}
public async Task Handle(HidePostCommand message)
{
Blog blog = await _blogReadOnlyRepository.GetBlog(message.Id);
blog.Enable();
await _serviceBus.Publish(blog.GetEvents());
}
}
}