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

32 lines
813 B
C#

using Jambo.Producer.Application.Commands;
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 CreatePostCommandHandler : IAsyncRequestHandler<CreateBlogCommand, Guid>
{
private readonly IPublisher bus;
public CreatePostCommandHandler(IPublisher bus)
{
this.bus = bus ?? throw new ArgumentNullException(nameof(bus));
}
public async Task<Guid> Handle(CreateBlogCommand command)
{
Blog blog = Blog.Create();
blog.Start();
blog.UpdateUrl(Url.Create(command.Url));
await bus.Publish(blog.GetEvents(), command.Header);
return blog.Id;
}
}
}