Exemplo n.º 1
0
        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);
            });
        }
Exemplo n.º 2
0
        public static void Handle(PersonMoved @event)
        {
            var model = Store.FirstOrDefault(x => x.Id == @event.ModelId);

            if (model == null)
            {
                throw new Exception("No model found for that Id");
            }
            model.Person.ZipCode = @event.ZipCode;
        }
Exemplo n.º 3
0
 public void Apply(PersonMoved @event)
 {
     DomainModel.Person.ZipCode = @event.ZipCode;
 }