示例#1
0
        public EventProjection() : base("Projections")
        {
            _projectMethods = new ProjectMethodCollection(GetType());
            _createMethods  = new CreateMethodCollection(GetType());

            ProjectionName = GetType().FullNameInCode();
        }
示例#2
0
        public EventProjection() : base("Projections")
        {
            _projectMethods = new ProjectMethodCollection(GetType());
            _createMethods  = new CreateMethodCollection(GetType());

            // TODO -- get fancier later
            ProjectionName = GetType().FullNameInCode();
        }
示例#3
0
        public V4AggregateProjection()
        {
            _createMethods       = new CreateMethodCollection(GetType(), typeof(T));
            _applyMethods        = new ApplyMethodCollection(GetType(), typeof(T));
            _shouldDeleteMethods = new ShouldDeleteMethodCollection(GetType(), typeof(T));

            ProjectionName = typeof(T).Name;
        }
示例#4
0
        public AggregateProjection() : base(typeof(T).NameInCode())
        {
            _createMethods       = new CreateMethodCollection(GetType(), typeof(T));
            _applyMethods        = new ApplyMethodCollection(GetType(), typeof(T));
            _shouldDeleteMethods = new ShouldDeleteMethodCollection(GetType(), typeof(T));

            ProjectionName = typeof(T).Name;

            Options.DeleteViewTypeOnTeardown <T>();
        }
示例#5
0
        internal static ILiveAggregator <T> Build <T>(StoreOptions options)
        {
            var mapping = options.Storage.MappingFor(typeof(T));

            var assembly = new GeneratedAssembly(new GenerationRules("Marten.Generated"));

            var applyMethods = new ApplyMethodCollection(typeof(T), typeof(T));

            // TODO -- this doesn't do very much right now.
            var createMethods = new CreateMethodCollection(typeof(T), typeof(T));

            assembly.Generation.Assemblies.Add(typeof(IMartenSession).Assembly);
            assembly.Generation.Assemblies.AddRange(applyMethods.ReferencedAssemblies());
            assembly.Generation.Assemblies.AddRange(createMethods.ReferencedAssemblies());

            var isAsync = applyMethods.IsAsync;

            assembly.Namespaces.Add("System.Linq");

            var liveBaseType = isAsync
                ? typeof(AsyncLiveAggregatorBase <>)
                : typeof(SyncLiveAggregatorBase <>);

            liveBaseType = liveBaseType.MakeGenericType(typeof(T));

            var liveType = assembly.AddType(typeof(T).NameInCode().Sanitize() + "LiveAggregation", liveBaseType);

            var overrideMethodName = isAsync ? "BuildAsync" : "Build";
            var buildMethod        = liveType.MethodFor(overrideMethodName);

            // TODO -- use constructor functions later
            // TODO -- use static Create() methods
            // TODO -- validate that there is some way to create the aggregate
            buildMethod.Frames.Code("if (!events.Any()) return null;");
            buildMethod.Frames.Add(new CallCreateAggregateFrame(createMethods));
            buildMethod.Frames.Add(new CallApplyAggregateFrame(applyMethods)
            {
                InsideForEach = true
            });

            buildMethod.Frames.Return(typeof(T));

            createMethods.BuildCreateMethod(liveType, mapping);
            applyMethods.BuildApplyMethod(liveType, mapping);

            var assemblyGenerator = new AssemblyGenerator();

            assemblyGenerator.ReferenceAssembly(typeof(IMartenSession).Assembly);
            assemblyGenerator.Compile(assembly);

            return((ILiveAggregator <T>)Activator.CreateInstance(liveType.CompiledType));
        }
        public AggregateProjection() : base(typeof(T).NameInCode())
        {
            _createMethods       = new CreateMethodCollection(GetType(), typeof(T));
            _applyMethods        = new ApplyMethodCollection(GetType(), typeof(T));
            _shouldDeleteMethods = new ShouldDeleteMethodCollection(GetType(), typeof(T));

            ProjectionName = typeof(T).Name;

            Options.DeleteViewTypeOnTeardown <T>();

            _allEventTypes = new Lazy <Type[]>(() =>
            {
                return(_createMethods.Methods.Concat(_applyMethods.Methods).Concat(_shouldDeleteMethods.Methods)
                       .Select(x => x.EventType).Concat(DeleteEvents).Distinct().ToArray());
            });
        }
        protected GeneratedAggregateProjectionBase(AggregationScope scope) : base(typeof(T).NameInCode())
        {
            _createMethods       = new CreateMethodCollection(GetType(), typeof(T));
            _applyMethods        = new ApplyMethodCollection(GetType(), typeof(T));
            _shouldDeleteMethods = new ShouldDeleteMethodCollection(GetType(), typeof(T));

            Options.DeleteViewTypeOnTeardown <T>();

            _allEventTypes = new Lazy <Type[]>(() =>
            {
                return(_createMethods.Methods.Concat(_applyMethods.Methods).Concat(_shouldDeleteMethods.Methods)
                       .Select(x => x.EventType).Concat(DeleteEvents).Concat(TransformedEvents).Distinct().ToArray());
            });


            _inlineAggregationHandlerType = GetType().ToSuffixedTypeName("InlineHandler");
            _liveAggregationTypeName      = GetType().ToSuffixedTypeName("LiveAggregation");
            _versioning = new AggregateVersioning <T>(scope);
        }
        public AggregateProjection() : base(typeof(T).NameInCode())
        {
            _createMethods       = new CreateMethodCollection(GetType(), typeof(T));
            _applyMethods        = new ApplyMethodCollection(GetType(), typeof(T));
            _shouldDeleteMethods = new ShouldDeleteMethodCollection(GetType(), typeof(T));

            ProjectionName = typeof(T).Name;

            Options.DeleteViewTypeOnTeardown <T>();

            _allEventTypes = new Lazy <Type[]>(() =>
            {
                return(_createMethods.Methods.Concat(_applyMethods.Methods).Concat(_shouldDeleteMethods.Methods)
                       .Select(x => x.EventType).Concat(DeleteEvents).Concat(TransformedEvents).Distinct().ToArray());
            });


            _inlineAggregationHandlerType = GetType().NameInCode().Sanitize() + "InlineHandler";
            _liveAggregationTypeName      = GetType().NameInCode().Sanitize() + "LiveAggregation";
        }
示例#9
0
        public EventProjection() : base("Projections")
        {
            _projectMethods = new ProjectMethodCollection(GetType());
            _createMethods  = new CreateMethodCollection(GetType());

            ProjectionName  = GetType().FullNameInCode();
            _inlineTypeName = GetType().ToSuffixedTypeName("InlineProjection");

            _generatedProjection = new Lazy <IProjection>(() =>
            {
                if (_generatedType == null)
                {
                    throw new InvalidOperationException("The EventProjection has not created its inner IProjection");
                }

                var projection = (IProjection)Activator.CreateInstance(_generatedType, this);
                foreach (var setter in _inlineType.Setters)
                {
                    setter.SetInitialValue(projection);
                }

                return(projection);
            });
        }