public CommandHandlerActor() { var aggregateActor = Context.ActorOf(Props.Create(() => new AggregateRootActor()), "AggregateActor"); Receive <CreatePerson>(x => { var personCreatedEvent = new PersonCreated(x.Model, Guid.NewGuid()); aggregateActor.Tell(personCreatedEvent, Self); }); Receive <ChangeAddress>(x => { var personMovedEvent = new PersonMoved(x.ZipCode, x.AggregateId, x.ModelId); aggregateActor.Tell(personMovedEvent, Self); }); Receive <ChangeName>(x => { var personRenamedEvent = new PersonRenamed(x.FirstName, x.LastName, x.AggregateId, x.ModelId); aggregateActor.Tell(personRenamedEvent, Self); }); Receive <RebuildAggregate>(x => { var aggregateRebuildEvent = new AggregateRebuildInitiated(x.AggregateId); aggregateActor.Tell(aggregateRebuildEvent, Self); }); }
public static void Handle(PersonCreated @event) { Store.Add(@event.Model); var model = @event.Model; Console.WriteLine("Person Saved to ReadStore: Id {0}, First Name {1}, Last Name {2}, Zip Code {3}", model.Id, model.Person.FirstName, model.Person.LastName, model.Person.ZipCode); }
public void Apply(PersonCreated @event) { DomainModel = @event.Model; }