@@ -49,23 +49,24 @@ public abstract class AggregateRoot<TAggregate, TIdentity, TAggregateState> : Re
4949 {
5050 private static readonly IReadOnlyDictionary < Type , Action < TAggregateState , IAggregateEvent > > ApplyMethodsFromState = typeof ( TAggregateState ) . GetAggregateStateEventApplyMethods < TAggregate , TIdentity , TAggregateState > ( ) ;
5151 private static readonly IReadOnlyDictionary < Type , Action < TAggregateState , IAggregateSnapshot > > HydrateMethodsFromState = typeof ( TAggregateState ) . GetAggregateSnapshotHydrateMethods < TAggregate , TIdentity , TAggregateState > ( ) ;
52- public static readonly IAggregateName AggregateName = typeof ( TAggregate ) . GetAggregateName ( ) ;
53- protected CircularBuffer < ISourceId > _previousSourceIds = new CircularBuffer < ISourceId > ( 100 ) ;
54- protected ICommand < TAggregate , TIdentity > PinnedCommand { get ; private set ; }
55- protected object PinnedReply { get ; private set ; }
52+ private static readonly IAggregateName AggregateName = typeof ( TAggregate ) . GetAggregateName ( ) ;
53+ private CircularBuffer < ISourceId > _previousSourceIds = new CircularBuffer < ISourceId > ( 100 ) ;
54+ private ICommand < TAggregate , TIdentity > PinnedCommand { get ; set ; }
55+ private object PinnedReply { get ; set ; }
5656
5757 protected ILoggingAdapter Logger { get ; }
58- protected IEventDefinitionService _eventDefinitionService ;
59- protected ISnapshotDefinitionService _snapshotDefinitionService ;
60- protected ISnapshotStrategy SnapshotStrategy { get ; set ; } = SnapshotNeverStrategy . Instance ;
61- public TAggregateState State { get ; }
58+ //TODO This should be private readonly.
59+ protected readonly IEventDefinitionService EventDefinitionService ;
60+ private readonly ISnapshotDefinitionService _snapshotDefinitionService ;
61+ private ISnapshotStrategy SnapshotStrategy { get ; set ; } = SnapshotNeverStrategy . Instance ;
62+ protected TAggregateState State { get ; }
6263 public IAggregateName Name => AggregateName ;
6364 public override string PersistenceId { get ; }
6465 public TIdentity Id { get ; }
6566 public long Version { get ; protected set ; }
6667 public bool IsNew => Version <= 0 ;
6768 public override Recovery Recovery => new Recovery ( SnapshotSelectionCriteria . Latest ) ;
68- public AggregateRootSettings Settings { get ; }
69+ private AggregateRootSettings Settings { get ; }
6970
7071 protected AggregateRoot ( TIdentity id )
7172 {
@@ -93,7 +94,7 @@ protected AggregateRoot(TIdentity id)
9394 }
9495
9596 PinnedCommand = null ;
96- _eventDefinitionService = new EventDefinitionService ( Logger ) ;
97+ EventDefinitionService = new EventDefinitionService ( Logger ) ;
9798 _snapshotDefinitionService = new SnapshotDefinitionService ( Logger ) ;
9899 Id = id ;
99100 PersistenceId = id . Value ;
@@ -161,8 +162,8 @@ public virtual CommittedEvent<TAggregate, TIdentity, TAggregateEvent> From<TAggr
161162 {
162163 throw new ArgumentNullException ( nameof ( aggregateEvent ) ) ;
163164 }
164- _eventDefinitionService . Load ( aggregateEvent . GetType ( ) ) ;
165- var eventDefinition = _eventDefinitionService . GetDefinition ( aggregateEvent . GetType ( ) ) ;
165+ EventDefinitionService . Load ( aggregateEvent . GetType ( ) ) ;
166+ var eventDefinition = EventDefinitionService . GetDefinition ( aggregateEvent . GetType ( ) ) ;
166167 var aggregateSequenceNumber = version + 1 ;
167168 var eventId = EventId . NewDeterministic (
168169 GuidFactories . Deterministic . Namespaces . Events ,
@@ -256,10 +257,7 @@ protected override bool AroundReceive(Receive receive, object message)
256257
257258 protected virtual void Reply ( object replyMessage )
258259 {
259- if ( Sender == ActorRefs . NoSender || Sender == ActorRefs . Nobody )
260- {
261- // do nothing
262- } else
260+ if ( ! Sender . IsNobody ( ) )
263261 {
264262 PinnedReply = replyMessage ;
265263 }
@@ -408,7 +406,7 @@ protected void Command<TCommand, TCommandHandler>(Predicate<TCommand> shouldHand
408406 }
409407
410408 }
411-
409+
412410 }
413411
414412}
0 commit comments