Skip to content

Instantly share code, notes, and snippets.

@rmaziarka
Last active January 6, 2018 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmaziarka/d3b0d39a3c1c1804641e19a0cff742ac to your computer and use it in GitHub Desktop.
Save rmaziarka/d3b0d39a3c1c1804641e19a0cff742ac to your computer and use it in GitHub Desktop.
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