Пример #1
0
        public static void SubscribeToCommand <TCommand>(this INybusConfigurator configurator, CommandReceivedAsync <TCommand> commandReceived)
            where TCommand : class, ICommand
        {
            var handler = new DelegateWrapperCommandHandler <TCommand>(commandReceived);

            SubscribeToCommand <TCommand, DelegateWrapperCommandHandler <TCommand> >(configurator, handler);
        }
Пример #2
0
        public static void SubscribeToEvent <TEvent>(this INybusConfigurator configurator, EventReceivedAsync <TEvent> eventReceived)
            where TEvent : class, IEvent
        {
            var handler = new DelegateWrapperEventHandler <TEvent>(eventReceived);

            SubscribeToEvent <TEvent, DelegateWrapperEventHandler <TEvent> >(configurator, handler);
        }
Пример #3
0
        public void Apply(INybusConfigurator nybus)
        {
            var options = new RabbitMqOptions();

            if (_configurationSectionName != null && nybus.Configuration.TryGetSection(_configurationSectionName, out var configurationSection))
            {
                configurationSection.Bind(options);
            }

            nybus.AddServiceConfiguration(sc => sc.AddSingleton(options));

            nybus.AddServiceConfiguration(sc => sc.AddTransient <IRabbitMqConfiguration>(sp =>
            {
                var factory = sp.GetRequiredService <IConfigurationFactory>();

                var op = sp.GetRequiredService <RabbitMqOptions>();

                var configuration = factory.Create(op);

                foreach (var configurationAction in _configurationActions)
                {
                    configurationAction?.Invoke(configuration);
                }

                return(configuration);
            }));

            foreach (var registration in _queueFactoryProviderRegistrations)
            {
                nybus.AddServiceConfiguration(registration);
            }
        }
Пример #4
0
        public static void UseInMemoryBusEngine(this INybusConfigurator configurator)
        {
            configurator.AddServiceConfiguration(svc => svc.AddSingleton <ISerializer, JsonSerializer>());

            configurator.AddServiceConfiguration(svc => svc.AddSingleton <IEnvelopeService, EnvelopeService>());

            configurator.UseBusEngine <InMemoryBusEngine>();
        }
Пример #5
0
        public static void SubscribeToEvent <TEvent, TEventHandler>(this INybusConfigurator configurator, TEventHandler handler)
            where TEvent : class, IEvent
            where TEventHandler : class, IEventHandler <TEvent>
        {
            configurator.AddSubscription(builder => builder.SubscribeToEvent <TEvent>(typeof(TEventHandler)));

            configurator.AddServiceConfiguration(services => services.AddSingleton(handler));
        }
Пример #6
0
 public static void SubscribeToEvent <TEvent>(this INybusConfigurator configurator, EventReceived <TEvent> eventReceived) where TEvent : class, IEvent
 {
     SubscribeToEvent <TEvent>(configurator, (dispatcher, context) =>
     {
         eventReceived(dispatcher, context);
         return(Task.CompletedTask);
     });
 }
Пример #7
0
        public static void SubscribeToCommand <TCommand, TCommandHandler>(this INybusConfigurator configurator, TCommandHandler handler)
            where TCommand : class, ICommand
            where TCommandHandler : class, ICommandHandler <TCommand>
        {
            configurator.AddSubscription(builder => builder.SubscribeToCommand <TCommand>(typeof(TCommandHandler)));

            configurator.AddServiceConfiguration(services => services.AddSingleton(handler));
        }
Пример #8
0
        public static void SubscribeToCommand <TCommand>(this INybusConfigurator configurator, CommandReceived <TCommand> commandReceived) where TCommand : class, ICommand
        {
            SubscribeToCommand <TCommand>(configurator, (dispatcher, context) =>
            {
                commandReceived(dispatcher, context);

                return(Task.CompletedTask);
            });
        }
Пример #9
0
        public static void UseBusEngine <TEngine>(this INybusConfigurator configurator, Action <IServiceCollection> configureServices = null)
            where TEngine : class, IBusEngine
        {
            configurator.AddServiceConfiguration(services => services.AddSingleton <IBusEngine, TEngine>());

            if (configureServices != null)
            {
                configurator.AddServiceConfiguration(configureServices);
            }
        }
Пример #10
0
 public static void RegisterErrorFilterProvider <TProvider>(this INybusConfigurator configurator, Func <IServiceProvider, IErrorFilterProvider> factory = null) where TProvider : class, IErrorFilterProvider
 {
     if (factory == null)
     {
         configurator.AddServiceConfiguration(sc => sc.AddSingleton <IErrorFilterProvider, TProvider>());
     }
     else
     {
         configurator.AddServiceConfiguration(sc => sc.AddSingleton(factory));
     }
 }
Пример #11
0
        public void UseBusEngine_registers_BusEngine(INybusConfigurator configurator, TestBusEngine engine)
        {
            IServiceCollection serviceCollection = new ServiceCollection();

            Mock.Get(configurator).Setup(p => p.AddServiceConfiguration(It.IsAny <Action <IServiceCollection> >())).Callback((Action <IServiceCollection> dlg) => dlg(serviceCollection));

            NybusConfiguratorExtensions.UseBusEngine <TestBusEngine>(configurator);

            var serviceProvider = serviceCollection.BuildServiceProvider();

            Assert.That(serviceProvider.GetRequiredService <IBusEngine>(), Is.InstanceOf <TestBusEngine>());
        }
Пример #12
0
        public static void UseRabbitMqBusEngine(this INybusConfigurator nybus, Action <IRabbitMqConfigurator> configure = null)
        {
            nybus.AddServiceConfiguration(svc => svc.AddSingleton <IConfigurationFactory, ConfigurationFactory>());

            nybus.AddServiceConfiguration(svc => svc.AddSingleton <IConnectionFactoryProviders, ConnectionFactoryProviders>());

            var configurator = new RabbitMqConfigurator();

            configurator.RegisterQueueFactoryProvider <StaticQueueFactoryProvider>();

            configurator.RegisterQueueFactoryProvider <TemporaryQueueFactoryProvider>();

            configure?.Invoke(configurator);

            configurator.Apply(nybus);

            nybus.UseBusEngine <RabbitMqBusEngine>();
        }
Пример #13
0
        public void ServiceConfigurator_delegate_is_registered(INybusConfigurator configurator, TestBusEngine engine, Action <IServiceCollection> serviceConfigurator)
        {
            NybusConfiguratorExtensions.UseBusEngine <TestBusEngine>(configurator, serviceConfigurator);

            Mock.Get(configurator).Verify(p => p.AddServiceConfiguration(serviceConfigurator));
        }
Пример #14
0
 public static void SubscribeToEvent <TEvent>(this INybusConfigurator configurator)
     where TEvent : class, IEvent
 {
     configurator.AddSubscription(builder => builder.SubscribeToEvent <TEvent>(typeof(IEventHandler <TEvent>)));
 }
Пример #15
0
 public static void SubscribeToCommand <TCommand>(this INybusConfigurator configurator)
     where TCommand : class, ICommand
 {
     configurator.AddSubscription(builder => builder.SubscribeToCommand <TCommand>(typeof(ICommandHandler <TCommand>)));
 }