Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class ProductAddedEventHandler: INotificationHandler<ProductAddedEvent>
{
private readonly IProductReadModelRepository _repo;
public ProductAddedEventHandler(IProductReadModelRepository repo)
{
_repo = repo;
}
public void Handle(ProductAddedEvent @event)
{
var product = new ProductReadModel(@event);
_repo.Insert(product);
}
}
public class ReviewAddedEventHandler : INotificationHandler<ReviewAddedEvent>
{
private readonly IProductReadModelRepository _repo;
public ReviewAddedEventHandler(IProductReadModelRepository repo)
{
_repo = repo;
}
public void Handle(ReviewAddedEvent @event)
{
var product = _repo.Find(@event.ProductId);
product.Apply(@event);
_repo.Update(product);
}
}
public class OrderCompletedEventHandler : INotificationHandler<OrderCompletedEvent>
{
private readonly IProductReadModelRepository _repo;
public OrderCompletedEventHandler(IProductReadModelRepository repo)
{
_repo = repo;
}
public void Handle(OrderCompletedEvent @event)
{
var product = _repo.Find(@event.ProductId);
product.Apply(@event);
_repo.Update(product);
}
}
public class FieldValueChangedEventHandler : INotificationHandler<FieldValueChangedEvent>
{
private readonly IProductReadModelRepository _repo;
public FieldValueChangedEventHandler(IProductReadModelRepository repo)
{
_repo = repo;
}
public void Handle(FieldValueChangedEvent @event)
{
var product = _repo.Find(@event.ProductId);
product.Apply(@event);
_repo.Update(product);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment