示例#1
0
        /// <summary>
        /// Levée d'un évènement.
        /// </summary>
        /// <typeparam name="AggregateT">Type de l'agrégat.</typeparam>
        /// <typeparam name="IndexT">Type de l'index.</typeparam>
        /// <param name="raisedEvent">Evènement.</param>
        /// <param name="applicationContext">Contexte de l'application.</param>
        /// <returns>Agrégat.</returns>
        public async Task <AggregateT> Raise <AggregateT, IndexT>(IEvent <AggregateT, IndexT> raisedEvent, IApplicationContext applicationContext)
            where AggregateT : IAggregate <IndexT>
            where IndexT : IComparable, IComparable <IndexT>, IEquatable <IndexT>
        {
            // Construction des informations sur l'évènement et sauvegarde.
            IEventInformation eventInformation = BuildEventInformation(raisedEvent, applicationContext.CurrentUser);
            // TODO : stokcage des évènements.

            // Recherche de la source de données pour le type d'agrégat.
            IRepository <AggregateT, IndexT> repository = repositoryService.GetRepository <AggregateT, IndexT>();

            // Recherche de l'agrégat et création s'il n'existe pas.
            AggregateT aggregate = await repository.GetByIdOrDefaultAsync(raisedEvent.AggregateId);

            if (aggregate == null)
            {
                // Construction de l'agrégat.
                aggregate = BuildAggregate <AggregateT, IndexT>();

                // Création d'un identifiant pour l'évènement.
                raisedEvent.AggregateId = await repository.GetNextAggregatetIdAsync(aggregate.GenerateNextId);
            }

            // Application des modifications.
            raisedEvent.Apply(aggregate);

            // Lancement en asynchrone de l'évènement pour prise en compte dans EventHandler.
            await ActivateEventHanlders(raisedEvent, aggregate);

            return(aggregate);
        }
示例#2
0
        public void Apply(IEvent @event)
        {
            if ([email protected](GetType()))
            {
                throw new Exception($"cant apply to {this.GetType()}");
            }

            @event.Apply((dynamic)this);

            OnEventApplied(@event);
        }
示例#3
0
        public void Apply(IEvent @event)
        {
            object aggregate;

            if (_items.TryGetValue(@event.AggregateID, out aggregate) == false)
            {
                _items[@event.AggregateID] = aggregate = _createBlank();
            }

            @event.Apply(aggregate, _aggregator);
        }
        public virtual bool AddAndApply(IEvent <T, TKey> item, T value)
        {
            if (Contains(item))
            {
                return(false);
            }

            item.Apply(value);
            Add(item);

            return(true);
        }
        /// <summary>
        /// Adds <see cref="item"/> to list.
        /// Applies <see cref="item"/> if <see cref="IMutationEvent{T}"/>
        /// or  <see cref="item"/> if <see cref="IOrderedEvent{TKey, TOrder}.Order"/> <see cref="CompareUtilities.GreaterOrEqualTo"/> <see cref="MaxOrder"/>.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="item"></param>
        /// <returns>Wether <see cref="item"/> is applied.</returns>
        public override bool AddAndApply(IEvent <T, TKey> item, T value)
        {
            Add(item);

            if (!(item is IOrderedEvent <TKey, TOrder>) ||
                item is IMutationEvent <T, TKey> ||
                (item is IOrderedEvent <TKey, TOrder> orderedEvent && CompareUtilities.GreaterOrEqualTo(orderedEvent.Order, MaxOrder)))
            {
                item.Apply(value);
                return(true);
            }

            return(false);
        }
示例#6
0
        public async Task <TAggregate> Raise <TAggregate>(IEvent <TAggregate> @event) where TAggregate : class, IAggregate
        {
            var eventInformation = this.BuildEventInformation(@event);

            await this.EventInformationRepository.Create(eventInformation);

            var aggregate = await this._dependencyResolver.Get <IRepository <TAggregate> >().GetByIdOrNull(@event.AggregateId);

            if (aggregate == null)
            {
                aggregate = this.BuildAggregate <TAggregate>();
            }

            @event.Apply(aggregate);

            await this.LaunchEventHandlers(aggregate, @event);

            return(aggregate);
        }
示例#7
0
        public void Apply <TAggregate>(IEvent <TKey, TAggregate> @event) where TAggregate : IAggregate <TKey>
        {
            @event.Apply((dynamic)this);

            OnEventApplied(@event);
        }
示例#8
0
        public void Apply(IEvent @event)
        {
            var aggregate = _items.GetOrAdd(@event.AggregateID.ToString(), key => _createBlank());

            @event.Apply(aggregate, _aggregator);
        }
 private void Apply(IEvent <Person> evnt)
 {
     evnt.Apply(this);
     unsavedEvents.Add(evnt);
 }
 public virtual void InsertAndApply(int index, IEvent <T, TKey> item, T value)
 {
     item.Apply(value);
     Insert(index, item);
 }