This repository has been archived by the owner on May 7, 2020. It is now read-only.
v2.1.0
Breaking Change
- There are several breaking changes about Domain Modelling; these are:
- AggregateRoot & Entity seperated each other
- AggregateRoot
Raise
method is removed(I know this is sad😢). You should use ApplyChange method.
For ex: Let's think about a Product AggregateRoot for CRUD DDD.
If Product Aggregate will raise any event then we have to define these events handling on its constructor, but these handlings concern Product AR. If you treat these events also as Domain Events you should write Handler for them to handle outside of AR.
protected Product()
{
Register<PriceChangedEvent>(@event =>
{
Price = @event.NewPrice;
});
Register<ProductCreatedEvent>(@event =>
{
Price = @event.Price;
ProductId = new ProductId(@event.Id);
Name = @event.Name;
});
}
public void ChangePrice(decimal price)
{
if (price <= 0) throw new ArgumentException("Price can not be equal or less zero", nameof(price));
ApplyChange(new PriceChangedEvent(price, ProductId.Id));
}
public static Product CreateProduct(string name, decimal price)
{
if (price <= 0) throw new ArgumentException("Price can not be equal or less zero", nameof(price));
var product = new Product();
var productId = new ProductId(Guid.NewGuid());
product.ApplyChange(new ProductCreatedEvent(name, price, productId.Id));
return product;
}
These changes can break your handling structure and existing components/properties of your events, if it does then consider your Domain Modelling because it might be wrong.