예제 #1
0
        public void Handle(RemoveSubThing command)
        {
            MyThing t = _repo.GetAggregate(command.AggregateId);

            t.ApplyEvent(new SubThingRemoved(t.AggregateId, command.SubThingId));
            _repo.SaveAggregate(t);
        }
예제 #2
0
        public void Handle(UpdateMyThing command)
        {
            MyThing t = _repo.GetAggregate(command.Id);

            t.ApplyEvent(new MyThingUpdated(t.AggregateId, command.Title));
            _repo.SaveAggregate(t);
        }
예제 #3
0
        public void Handle(AddSubThing command)
        {
            MyThing t = _repo.GetAggregate(command.AggregateId);

            t.ApplyEvent(new MySubThingAdded(t.AggregateId, command.Subthing));
            _repo.SaveAggregate(t);
        }
예제 #4
0
        public void Handle(CreateMyThing command)
        {
            MyThing t = new MyThing(command.AggregateId, command.Title);

            _repo.SaveAggregate(t);

            var a = 1;
        }
예제 #5
0
        public void AggTest()
        {
            //InMemoryEventStorage eventStore = new InMemoryEventStorage();
            //IAggregateRepository<MyThing> repo = new AggregateRepository<MyThing>(eventStore);
            //MyThingCommandHandler handler = new MyThingCommandHandler(repo);

            Guid id = Guid.NewGuid();

            CreateMyThing command = new CreateMyThing(id, "Peter");

            bus.Send(command);

            var     repo  = container.GetInstance <IAggregateRepository <MyThing> >();
            MyThing thing = repo.GetAggregate(id);

            bus.Send(new UpdateMyThing(id, "The new TIIIITLE!!!"));

            MyThing thing2 = repo.GetAggregate(id);

            bus.Send(new UpdateMyThing(id, "The new TIIIITLE!!!2"));
            bus.Send(new UpdateMyThing(id, "The new TIIIITLE!!!3"));
            bus.Send(new UpdateMyThing(id, "The new TIIIITLE!!!4"));

            MyThing thing3 = repo.GetAggregate(id);

            bus.Send(new AddSubThing(id, new MySubThing("Hej")));
            bus.Send(new AddSubThing(id, new MySubThing("Hopp")));

            MyThing thing4 = repo.GetAggregate(id);

            var st = thing4.SubThings.ToList().First();

            bus.Send(new RemoveSubThing(id, st.Id));

            MyThing thing5 = repo.GetAggregate(id);

            bus.Send(new UpdateMyThing(id, ""));

            MyThing thing6 = repo.GetAggregate(id);

            var a = 1;
        }