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); }
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); }
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); } }
public static void UseInMemoryBusEngine(this INybusConfigurator configurator) { configurator.AddServiceConfiguration(svc => svc.AddSingleton <ISerializer, JsonSerializer>()); configurator.AddServiceConfiguration(svc => svc.AddSingleton <IEnvelopeService, EnvelopeService>()); configurator.UseBusEngine <InMemoryBusEngine>(); }
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)); }
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); }); }
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)); }
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); }); }
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); } }
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)); } }
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>()); }
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>(); }
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)); }
public static void SubscribeToEvent <TEvent>(this INybusConfigurator configurator) where TEvent : class, IEvent { configurator.AddSubscription(builder => builder.SubscribeToEvent <TEvent>(typeof(IEventHandler <TEvent>))); }
public static void SubscribeToCommand <TCommand>(this INybusConfigurator configurator) where TCommand : class, ICommand { configurator.AddSubscription(builder => builder.SubscribeToCommand <TCommand>(typeof(ICommandHandler <TCommand>))); }