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

32 lines
1.1 KiB
C#

using Jambo.Domain.Aggregates.Blogs;
using Jambo.Domain.Aggregates.Blogs.Events;
using Jambo.Domain.Aggregates.Posts;
using MediatR;
using System;
using System.Threading.Tasks;
namespace Jambo.Application.DomainEventHandlers.Posts
{
public class PostCreatedEventHandler : IAsyncNotificationHandler<BlogCreatedDomainEvent>
{
private readonly IPostReadOnlyRepository _postReadOnlyRepository;
private readonly IPostWriteOnlyRepository _postWriteOnlyRepository;
public PostCreatedEventHandler(
IPostReadOnlyRepository postReadOnlyRepository,
IPostWriteOnlyRepository postWriteOnlyRepository)
{
_postReadOnlyRepository = postReadOnlyRepository ??
throw new ArgumentNullException(nameof(postReadOnlyRepository));
_postWriteOnlyRepository = postWriteOnlyRepository ??
throw new ArgumentNullException(nameof(postWriteOnlyRepository));
}
public async Task Handle(BlogCreatedDomainEvent message)
{
Post post = new Post(message.AggregateRootId);
await _postWriteOnlyRepository.AddPost(post);
}
}
}