-
-
Save MarkNijhof/503820 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Fohjin.DDD.Domain.Client | |
{ | |
public class Client : BaseAggregateRoot<IDomainEvent>, IOrginator | |
{ | |
private Address _address; | |
public Client() | |
{ | |
registerEvents(); | |
} | |
public void ClientMoved(Address newAddress) | |
{ | |
Apply(new ClientMovedEvent(newAddress.Street, newAddress.StreetNumber, newAddress.PostalCode, newAddress.City)); | |
} | |
IMemento IOrginator.CreateMemento() | |
{ | |
return new ClientMemento(Id, Version, _address.Street, _address.StreetNumber, _address.PostalCode, _address.City); | |
} | |
void IOrginator.SetMemento(IMemento memento) | |
{ | |
var clientMemento = (ClientMemento) memento; | |
Id = clientMemento.Id; | |
Version = clientMemento.Version; | |
_address = new Address(clientMemento.Street, clientMemento.StreetNumber, clientMemento.PostalCode, clientMemento.City); | |
} | |
private void registerEvents() | |
{ | |
RegisterEvent<ClientMovedEvent>(onNewClientMoved); | |
} | |
private void onNewClientMoved(ClientMovedEvent clientMovedEvent) | |
{ | |
_address = new Address(clientMovedEvent.Street, clientMovedEvent.StreetNumber, clientMovedEvent.PostalCode, clientMovedEvent.City); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Fohjin.DDD.Domain.Client | |
{ | |
public class Client | |
{ | |
protected virtual void Apply(object @event) { } | |
protected IEnumerable<Type> RegisteredEvents() | |
{ | |
yield return typeof(ClientMovedEvent); | |
} | |
protected virtual Address Address { get; set; } | |
public void ClientMoved(Address newAddress) | |
{ | |
Apply(new ClientMovedEvent(newAddress)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment