Exemplo n.º 1
0
        private PersistableEntityBase(IRecorder recorder, IIdentifierFactory idFactory, Identifier identifier)
        {
            recorder.GuardAgainstNull(nameof(recorder));
            idFactory.GuardAgainstNull(nameof(idFactory));
            identifier.GuardAgainstNull(nameof(identifier));
            Recorder  = recorder;
            IdFactory = idFactory;
            Id        = identifier;

            var isInstantiating = identifier == Identifier.Empty();
            var now             = DateTime.UtcNow;

            LastPersistedAtUtc = null;
            CreatedAtUtc       = isInstantiating
                ? now
                : DateTime.MinValue;
            LastModifiedAtUtc = isInstantiating
                ? now
                : DateTime.MinValue;
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Creates a new instance of the aggregate with the specified <see cref="Identifier" />,
        ///     used during persistence instantiation. Does not raise any create event.
        /// </summary>
        protected AggregateRootBase(ILogger logger, IIdentifierFactory idFactory, Identifier identifier)
        {
            logger.GuardAgainstNull(nameof(logger));
            idFactory.GuardAgainstNull(nameof(idFactory));
            identifier.GuardAgainstNull(nameof(identifier));
            Logger               = logger;
            IdFactory            = idFactory;
            Id                   = identifier;
            this.events          = new List <IChangeEvent>();
            this.isInstantiating = identifier == Identifier.Empty();

            var now = DateTime.UtcNow;

            LastPersistedAtUtc = null;
            CreatedAtUtc       = this.isInstantiating
                ? now
                : DateTime.MinValue;
            LastModifiedAtUtc = this.isInstantiating
                ? now
                : DateTime.MinValue;
            ChangeVersion = 0;
        }
Exemplo n.º 3
0
        protected AggregateRootBase(ILogger logger, IIdentifierFactory idFactory,
                                    Func <Identifier, IChangeEvent> createdEventFactory) : this(logger, idFactory,
                                                                                                Identifier.Empty())

        {
            createdEventFactory.GuardAgainstNull(nameof(createdEventFactory));

            Id = idFactory.Create(this);
            RaiseCreateEvent(createdEventFactory(Id));
        }
Exemplo n.º 4
0
 protected PersistableEntityBase(IRecorder recorder, IIdentifierFactory idFactory)
     : this(recorder, idFactory, Identifier.Empty())
 {
     Id = idFactory.Create(this);
 }