Esempio n. 1
0
        private GeneratedMethod buildApplyEventMethod()
        {
            var method = _inlineGeneratedType.MethodFor(nameof(AggregationRuntime <string, string> .ApplyEvent));

            // This gets you the EventSlice aggregate Id

            method.DerivedVariables.Add(new Variable(_aggregateMapping.IdType,
                                                     $"slice.{nameof(EventSlice<string, string>.Id)}"));
            method.DerivedVariables.Add(Variable.For <Tenant>($"slice.{nameof(EventSlice<string, string>.Tenant)}"));
            method.DerivedVariables.Add(Variable.For <Tenant>($"slice.{nameof(EventSlice<string, string>.Tenant)}"));
            method.DerivedVariables.Add(Variable.For <IEvent>("@event"));
            method.DerivedVariables.Add(
                Variable.For <IMartenSession>($"({typeof(IMartenSession).FullNameInCode()})session"));
            method.DerivedVariables.Add(Variable.For <IQuerySession>("session"));
            method.DerivedVariables.Add(
                Variable.For <IAggregateProjection>(nameof(AggregationRuntime <string, string> .Projection)));


            var eventHandlers = new LightweightCache <Type, AggregateEventProcessingFrame>(
                eventType => new AggregateEventProcessingFrame(typeof(T), eventType));

            foreach (var deleteEvent in DeleteEvents)
            {
                eventHandlers[deleteEvent].AlwaysDeletes = true;
            }

            foreach (var slot in _applyMethods.Methods)
            {
                eventHandlers[slot.EventType].Apply = new ApplyMethodCall(slot);
            }

            foreach (var slot in _createMethods.Methods)
            {
                eventHandlers[slot.EventType].CreationFrame = slot.Method is ConstructorInfo
                    ? new AggregateConstructorFrame(slot)
                    : new CreateAggregateFrame(slot);
            }

            foreach (var slot in _shouldDeleteMethods.Methods)
            {
                eventHandlers[slot.EventType].Deletion = new ShouldDeleteFrame(slot);
            }

            var frames = eventHandlers.OfType <EventProcessingFrame>().ToList();

            frames.Sort(new EventTypeComparer());
            var patternMatching = new EventTypePatternMatchFrame(frames);

            method.Frames.Add(patternMatching);

            method.Frames.Code("return aggregate;");

            return(method);
        }
Esempio n. 2
0
 public void Dispose()
 {
     _reporters.OfType <IDisposable>().Each(x => x.Dispose());
 }