Ejemplo n.º 1
0
        /// <summary>
        ///     Adds a module to the current pipeline that replaces event with a projection.
        /// </summary>
        /// <remarks>
        ///     Projections are useful when an event needs to be serialized in order to reduce
        ///     the size and the complexity of the serialization output.
        /// </remarks>
        /// <typeparam name="TEvent">The type of the event.</typeparam>
        /// <typeparam name="TToEvent">The type of the projected event.</typeparam>
        /// <param name="eventPipelineConfigurator">
        ///     The <see cref="EventPipelineConfigurator{TEvent}"/> for the pipeline being configured.
        /// </param>
        /// <param name="eventConverter">
        ///     A <see cref="Func{TEvent, TToEvent}"/> that takes the event as input and returns a new object.
        /// </param>
        /// <returns>
        ///     A new <see cref="EventPipelineConfigurator{TToEvent}"/> instance so that multiple calls can be chained.
        /// </returns>
        public static EventPipelineConfigurator <TToEvent> ThenIsProjected <TEvent, TToEvent>(
            this EventPipelineConfigurator <TEvent> eventPipelineConfigurator,
            Func <TEvent, TToEvent> eventConverter
            )
            where TEvent : class
            where TToEvent : class
        {
            if (eventPipelineConfigurator == null)
            {
                throw new ArgumentNullException(nameof(eventPipelineConfigurator));
            }
            if (eventConverter == null)
            {
                throw new ArgumentNullException(nameof(eventConverter));
            }

            var projectionPipelineModuleConfig = new ProjectionPipelineModuleConfig(
                new EventProjection <TEvent, TToEvent>(eventConverter)
                );

            eventPipelineConfigurator
            .Get <IPipeline>()
            .AddModule <ProjectionPipelineModule, ProjectionPipelineModuleConfig>(
                projectionPipelineModuleConfig
                );

            return(new EventPipelineConfigurator <TToEvent>(
                       eventPipelineConfigurator.Get <IServiceProvider>(),
                       eventPipelineConfigurator.Get <IPipeline>()
                       ));
        }
        /// <summary>
        ///     Adds module to the current pipeline that queues the event in a queue
        ///     and pauses the execution of the current pipeline until the event is dequeued.
        /// </summary>
        /// <typeparam name="TEvent">The type of the event.</typeparam>
        /// <param name="eventPipelineConfigurator">
        ///     The <see cref="EventPipelineConfigurator{TEvent}"/> for the pipeline being configured.
        /// </param>
        /// <param name="queueName">The name of the queue.</param>
        /// <returns>
        ///     The same <see cref="EventPipelineConfigurator{TEvent}"/> instance so that multiple calls can be chained.
        /// </returns>
        public static EventPipelineConfigurator <TEvent> ThenIsQueuedTo <TEvent>(
            this EventPipelineConfigurator <TEvent> eventPipelineConfigurator,
            string queueName
            )
            where TEvent : class
        {
            if (eventPipelineConfigurator == null)
            {
                throw new ArgumentNullException(nameof(eventPipelineConfigurator));
            }
            if (queueName == null)
            {
                throw new ArgumentNullException(nameof(queueName));
            }

            var eventsQueueNamesService = eventPipelineConfigurator
                                          .Get <IServiceProvider>()
                                          .GetRequiredService <IEventsQueueNamesService>();

            eventsQueueNamesService.RegisterQueueNameIfNotExists(queueName);

            eventPipelineConfigurator
            .Get <IPipeline>()
            .AddModule <EnqueuePipelineModule, EnqueuePipelineModuleConfig>(
                new EnqueuePipelineModuleConfig
            {
                QueueName = queueName
            }
                );

            return(eventPipelineConfigurator);
        }
        public void Ctor_WithAllParameters_ShouldSetPropertiesFromParameters()
        {
            var eventPipelineConfigurator = new EventPipelineConfigurator <object>(
                _serviceProviderMock.Object,
                _pipeline
                );

            var pipeline        = eventPipelineConfigurator.Get <IPipeline>();
            var serviceProvider = eventPipelineConfigurator.Get <IServiceProvider>();

            Assert.That(pipeline, Is.EqualTo(_pipeline));
            Assert.That(serviceProvider, Is.EqualTo(_serviceProviderMock.Object));
        }
        public void Ctor_WithEventConfigurator_ShouldInheritPropertyValuesFromEventConfigurator()
        {
            var eventPipelineConfigurator = new EventPipelineConfigurator <object>(
                _pipeline,
                _eventConfigurator
                );

            var pipeline        = eventPipelineConfigurator.Get <IPipeline>();
            var serviceProvider = eventPipelineConfigurator.Get <IServiceProvider>();

            Assert.That(pipeline, Is.EqualTo(_pipeline));
            Assert.That(serviceProvider, Is.EqualTo(_serviceProviderMock.Object));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Adds a module to the current pipeline that publishes the event to all the global subscriptions using a transmission method
        ///     configurable with the configurePublishTransmission parameter.
        /// </summary>
        /// <remarks>
        ///     This method can be used to configure a publication to multiple application instances with this <see cref="EventsContext"/>
        /// </remarks>
        /// <typeparam name="TEvent">The type of the event.</typeparam>
        /// <param name="eventPipelineConfigurator">
        ///     The <see cref="EventPipelineConfigurator{TEvent}"/> for the pipeline being configured.
        /// </param>
        /// <param name="configurePublishTransmission">A delegate for configuring how the event is transmitted.</param>
        /// <returns>The same <see cref="EventPipelineConfigurator{TEvent}"/> instance so that multiple calls can be chained.</returns>
        public static EventPipelineConfigurator <TEvent> ThenIsPublishedToGlobalSubscriptions <TEvent>(
            this EventPipelineConfigurator <TEvent> eventPipelineConfigurator,
            Func <ConfigureTransmission, IPublishTransmissionConfiguration> configurePublishTransmission
            )
            where TEvent : class
        {
            if (configurePublishTransmission == null)
            {
                throw new ArgumentNullException(nameof(configurePublishTransmission));
            }

            var globalPublishingOptionsFactory = new ConfigureTransmission();
            var senderTypeConfiguration        = configurePublishTransmission(globalPublishingOptionsFactory);
            var moduleConfig = new GlobalPublishPipelineModuleConfig
            {
                SenderType = senderTypeConfiguration.SenderType
            };

            if (moduleConfig.SenderType != null)
            {
                var serviceProvider   = eventPipelineConfigurator.Get <IServiceProvider>();
                var eventSenderExists = serviceProvider
                                        .GetServices <IEventSender>()
                                        .Any(x => x.GetType() == moduleConfig.SenderType);

                if (!eventSenderExists)
                {
                    throw new EventTransmissionPluginIsNotConfiguredException();
                }
            }

            eventPipelineConfigurator
            .Get <IPipeline>()
            .AddModule <GlobalPublishPipelineModule, GlobalPublishPipelineModuleConfig>(
                moduleConfig
                );

            return(eventPipelineConfigurator);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Adds a module to the current pipeline that publishes the event to all the subscriptions in scope locally.
        /// </summary>
        /// <typeparam name="TEvent">The type of the event.</typeparam>
        /// <param name="eventPipelineConfigurator">
        ///     The <see cref="EventPipelineConfigurator{TEvent}"/> for the pipeline being configured.
        /// </param>
        /// <returns>The same <see cref="EventPipelineConfigurator{TEvent}"/> instance so that multiple calls can be chained.</returns>
        public static EventPipelineConfigurator <TEvent> ThenIsPublishedToScopedSubscriptions <TEvent>(
            this EventPipelineConfigurator <TEvent> eventPipelineConfigurator
            )
            where TEvent : class
        {
            if (eventPipelineConfigurator == null)
            {
                throw new ArgumentNullException(nameof(eventPipelineConfigurator));
            }

            eventPipelineConfigurator
            .Get <IPipeline>()
            .AddModule <ScopedPublishPipelineModule, ScopedPublishPipelineModuleConfig>(
                new ScopedPublishPipelineModuleConfig()
                );

            return(eventPipelineConfigurator);
        }
        /// <summary>
        ///     Adds an event filtering module to the current pipeline.
        /// </summary>
        /// <typeparam name="TEvent">The type of the event.</typeparam>
        /// <param name="eventPipelineConfigurator">
        ///     The <see cref="EventPipelineConfigurator{TEvent}"/> for the pipeline being configured.
        /// </param>
        /// <param name="filter">
        ///     A <see cref="Func{TEvent, TResult}"/> that takes the event
        ///     as input and returns false if it should be filtered
        ///     (When an event is filtered any module configured after the filter won't be invoked).
        /// </param>
        /// <returns>
        ///     The same <see cref="EventPipelineConfigurator{TEvent}"/> instance so that multiple calls can be chained.
        /// </returns>
        public static EventPipelineConfigurator <TEvent> ThenIsFiltered <TEvent>(
            this EventPipelineConfigurator <TEvent> eventPipelineConfigurator,
            Func <TEvent, bool> filter
            )
            where TEvent : class
        {
            if (eventPipelineConfigurator == null)
            {
                throw new ArgumentNullException(nameof(eventPipelineConfigurator));
            }
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            eventPipelineConfigurator.Get <IPipeline>()
            .AddModule <FilterPipelineModule, FilterPipelineModuleConfig>(
                new FilterPipelineModuleConfig(pipedEvent => filter((TEvent)pipedEvent))
                );

            return(eventPipelineConfigurator);
        }