コード例 #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
ファイル: Projector.cs プロジェクト: OwenMcDonnell/Crispin
        public void Apply(IEvent @event)
        {
            object aggregate;

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

            @event.Apply(aggregate, _aggregator);
        }
コード例 #4
0
        public virtual bool AddAndApply(IEvent <T, TKey> item, T value)
        {
            if (Contains(item))
            {
                return(false);
            }

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

            return(true);
        }
コード例 #5
0
        /// <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);
        }
コード例 #9
0
 private void Apply(IEvent <Person> evnt)
 {
     evnt.Apply(this);
     unsavedEvents.Add(evnt);
 }
コード例 #10
0
 public virtual void InsertAndApply(int index, IEvent <T, TKey> item, T value)
 {
     item.Apply(value);
     Insert(index, item);
 }