public IBus CreateBus() { if (_configuration == null) { throw new InvalidOperationException("The CreateBus() method was called with no configuration (Call .WithConfiguration(...) first)"); } Container.Configure(x => x.AddRegistry <ZebusRegistry>()); Container.Configure(x => { x.ForSingletonOf <IBusConfiguration>().Use(_configuration); x.ForSingletonOf <IZmqTransportConfiguration>().Use(_transportConfiguration); x.ForSingletonOf <IMessageDispatcher>().Use("MessageDispatcher factory", ctx => { var dispatcher = new MessageDispatcher(ctx.GetAllInstances <IMessageHandlerInvokerLoader>().ToArray(), ctx.GetInstance <IDispatchQueueFactory>()); dispatcher.ConfigureHandlerFilter(assembly => _scanTargets.Any(scanTarget => scanTarget.Matches(assembly))); dispatcher.ConfigureAssemblyFilter(type => _scanTargets.Any(scanTarget => scanTarget.Matches(type))); return(dispatcher); }); }); foreach (var configurationAction in _configurationActions) { Container.Configure(configurationAction); } var bus = Container.GetInstance <IBus>(); bus.Configure(PeerId, _environment); return(bus); }
public void should_filter_handlers() { _messageDispatcher.ConfigureHandlerFilter(x => x == typeof(ScanCommandHandler1)); _messageDispatcher.LoadMessageHandlerInvokers(); var types = _messageDispatcher.GetMessageHanlerInvokers(); types.ShouldNotContain(x => x.MessageHandlerType != typeof(ScanCommandHandler1)); }
private MessageDispatcher CreateAndStartDispatcher(IDispatchQueueFactory dispatchQueueFactory) { var messageDispatcher = new MessageDispatcher(new IMessageHandlerInvokerLoader[] { new SyncMessageHandlerInvokerLoader(_containerMock.Object), new AsyncMessageHandlerInvokerLoader(_containerMock.Object), }, dispatchQueueFactory); messageDispatcher.ConfigureAssemblyFilter(x => x == GetType().Assembly); messageDispatcher.ConfigureHandlerFilter(type => type != typeof(SyncMessageHandlerInvokerLoaderTests.WrongAsyncHandler)); messageDispatcher.Start(); return(messageDispatcher); }