Пример #1
0
        /// <summary>
        /// save event to db then apply event to state
        /// snapshot will be created for every 20 events
        /// Returns id of the newly applied event(from db)
        /// </summary>
        protected async Task <long> ApplyEvent(TEvent @event, long?rootEventId = null, long?parentEventId = null)
        {
            // apply event to EventSource
            var eventId = await EventSource.ApplyEvent(@event, rootEventId, parentEventId);

            // does this aggregate has aggregate stream settings
            if (_hasAggregateStream)
            {
                // notify AggregateStreamGrain about new event
                var aggregateGrain = GrainFactory.GetGrain <IAggregateStreamGrain>(_aggregateName);
                // fire and forget request
                aggregateGrain.InvokeOneWay(handler => handler.Notify(eventId));
            }
            // return eventId
            return(eventId);
        }