Пример #1
0
        /// <summary>
        /// Register a projection to the Marten configuration
        /// </summary>
        /// <param name="projection">Value values are Inline/Async, The default is Inline</param>
        /// <param name="lifecycle"></param>
        /// <param name="projectionName">Overwrite the named identity of this projection. This is valuable if using the projection asynchonously</param>
        /// <param name="asyncConfiguration">Optional configuration including teardown instructions for the usage of this projection within the async projection daempon</param>
        public void Add(IProjection projection, ProjectionLifecycle lifecycle = ProjectionLifecycle.Inline,
                        string projectionName = null, Action <AsyncOptions> asyncConfiguration = null)
        {
            if (lifecycle == ProjectionLifecycle.Live)
            {
                throw new ArgumentOutOfRangeException(nameof(lifecycle),
                                                      $"{nameof(ProjectionLifecycle.Live)} cannot be used for IProjection");
            }

            if (projection is ProjectionBase p)
            {
                p.AssembleAndAssertValidity();
                p.Lifecycle = lifecycle;
            }

            if (projection is IProjectionSource source)
            {
                asyncConfiguration?.Invoke(source.Options);
                All.Add(source);
            }
            else
            {
                var wrapper = new ProjectionWrapper(projection, lifecycle);
                if (projectionName.IsNotEmpty())
                {
                    wrapper.ProjectionName = projectionName;
                }

                asyncConfiguration?.Invoke(wrapper.Options);
                All.Add(wrapper);
            }
        }
Пример #2
0
        /// <summary>
        /// Register a projection to the Marten configuration
        /// </summary>
        /// <param name="projection">Value values are Inline/Async, The default is Inline</param>
        /// <param name="lifecycle"></param>
        /// <param name="projectionName">Overwrite the named identity of this projection. This is valuable if using the projection asynchonously</param>
        /// <param name="asyncConfiguration">Optional configuration including teardown instructions for the usage of this projection within the async projection daempon</param>
        public void Add(IProjection projection, ProjectionLifecycle lifecycle = ProjectionLifecycle.Inline,
                        string projectionName = null, Action <AsyncOptions> asyncConfiguration = null)
        {
            if (lifecycle == ProjectionLifecycle.Live)
            {
                throw new ArgumentOutOfRangeException(nameof(lifecycle),
                                                      $"{nameof(ProjectionLifecycle.Live)} cannot be used for IProjection");
            }


            var wrapper = new ProjectionWrapper(projection, lifecycle);

            if (projectionName.IsNotEmpty())
            {
                wrapper.ProjectionName = projectionName;
            }

            asyncConfiguration?.Invoke(wrapper.Options);
            All.Add(wrapper);
        }