Пример #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);
            });
        }
Пример #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;
        }
Пример #3
0
 public void Apply(PersonMoved @event)
 {
     DomainModel.Person.ZipCode = @event.ZipCode;
 }