Ejemplo n.º 1
0
        public void Apply(IEvent evnt)
        {
            if (String.IsNullOrEmpty(evnt.Id))
            {
                throw new Exception(String.Format("Event {0} has null (or empty) ID property. Make sure you specify it on event creation", evnt.GetType().FullName));
            }

            StateSpooler.Spool((AggregateState)_state, evnt);
            _changes.Add(evnt);
        }
Ejemplo n.º 2
0
        public TAggregate GetById <TAggregate>(String id)
            where TAggregate : Aggregate
        {
            if (String.IsNullOrEmpty(id))
            {
                throw new ArgumentException(String.Format(
                                                "Aggregate ID was not specified when trying to get by id {0} aggregate", typeof(TAggregate).FullName));
            }

            var transitions = _transitionStorage.GetTransitions(id, 0, int.MaxValue);

            var aggregate = AggregateCreator.CreateAggregateRoot <TAggregate>();
            var state     = AggregateCreator.CreateAggregateState(typeof(TAggregate));

            StateSpooler.Spool((AggregateState)state, transitions);
            aggregate.Setup(state, transitions.Count == 0 ? 0 : transitions.Last().Id.Version);

            return(aggregate);
        }