public void LoadsFromHistory(IEnumerable <IEvent> events) { var myevents = events as IEvent[] ?? events.ToArray(); if (myevents.Any()) { this.Id = myevents.First().AggregateId; Logger.DebugFormat("Loading {0} events from history on {1}", myevents.Count(), this.Id); foreach (var e in myevents) { this.Apply(e, false); } } else { Logger.DebugFormat("Loaded empty aggregate on id {0}", this.Id); } }
internal void Mutate(IEvent e) { Logger.DebugFormat("Apply state {0} (mutate)", e); // .NET magic to call one of the 'When' handlers with // matching signature try { ((dynamic)this).When((dynamic)e); } catch (RuntimeBinderException) { throw new Exception(string.Format("The State {0} should implement IStateEvent<{1}> even if no state change is required", this.GetType().FullName, e.GetType().Name)); } }