protected DomainEventSourcedActor(IConstructAggregates aggregateConstructor, IConstructSnapshots snapshotsConstructor, ISnapshotsPersistencePolicy policy) { _snapshotsConstructor = snapshotsConstructor; _snapshotsPolicy = policy; _snapshotsSaveTracker = (policy as ISnapshotsSavePolicy).Tracking; _snapshotsDeleteTracker = (policy as ISnapshotsDeletePolicy).Tracking; PersistenceId = Self.Path.Name; Id = EntityActorName.Parse <T>(Self.Path.Name).Id; State = (T)aggregateConstructor.Build(typeof(T), Id, null); Monitor = new ActorMonitor(Context, typeof(T).Name); Behavior = new BehaviorQueue(Become); DefaultBehavior(); Recover <DomainEvent>(e => State.Apply(e)); Recover <SnapshotOffer>(offer => { _snapshotsPolicy.MarkSnapshotApplied(offer.Metadata.SequenceNr); State = (T)aggregateConstructor.Build(typeof(T), Id, (IMemento)offer.Snapshot); Log.Debug("Built state from snapshot #{snapshotNum}", offer.Metadata.SequenceNr); }); Recover <RecoveryCompleted>(message => { Log.Debug("Recovery completed"); NotifyPersistenceWatchers(message); }); }
public AggregateActor() { Behavior = new BehaviorQueue(Become); Behavior.Become(AwaitingCommandBehavior, nameof(AwaitingCommandBehavior)); PersistenceId = Self.Path.Name; Id = EntityActorName.Parse <TAggregate>(Self.Path.Name).Id; var aggregateExtensions = Context.System.GetAggregatesExtension(); var dependencies = aggregateExtensions.GetDependencies <TAggregate>(); Aggregate = dependencies.AggregateFactory.Build(); Recover <DomainEvent>(e => Aggregate.Apply(e)); }