Created
June 8, 2015 13:49
-
-
Save Danthar/12f1b2dd229d4e58927a to your computer and use it in GitHub Desktop.
Start werkzaamheden - command based - vanaf scratch poc
This file contains 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
public class WerkbonAggregate { | |
private WerkbonModel _state; | |
private List<object> _uncommittedEvents = new List<object>(); | |
public WerkbonAggregate(WerkbonModel state) { | |
_state = state; | |
} | |
public void StartWerkzaamHeden(DateTime gestartOp){ | |
if(_state.WerkbonStatus != WerkbonStatus.Dispatched) | |
throw new InvalidOperationException("Kan geen werkzaamheden starten op deze werkbon.") | |
//update state | |
//publish event | |
Publish(new WerkbonWerkzaamhedenGestart() { | |
Id = _state.Id, | |
WerkzaamHedenGestart = gestartOp | |
}) | |
} | |
private void Publish(object e) | |
{ | |
_uncommittedEvents.Add(e); | |
} | |
} | |
public class WerkbonApplicationService | |
{ | |
private IWerkbonDao _repository; | |
public WerkbonApplicationService(IWerkbonDao dao) { | |
_repository = dao; | |
} | |
public Object When(StartWerkbonWerkzaamhedenCommand cmd) { | |
var aggregate = _repository.FindWerkbon(cmd.Id); | |
aggregate.StartWerkzaamHeden(cmd.GestartOp); | |
_repository.Save(aggregate); | |
} | |
} | |
//https://lostechies.com/gabrielschenker/2015/04/28/ddd-applied/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment