private static void RegisterPropertiesFromConfigurationObject(PoorMansIoC container, object configuration) { foreach (var prop in configuration.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)) { var value = prop.GetValue(configuration); if (value == null) { continue; } container.Register(value); } }
internal static void RegisterPropertiesFromConfigurationObject(this PoorMansIoC container, INimbusConfiguration configuration) { configuration.RegisterWith(container); configuration .GetType() .GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance) .Where(p => typeof(ISetting).IsAssignableFrom(p.PropertyType)) .Select(p => p.GetValue(configuration)) .Do(o => container.Register(o)) .Done(); configuration .GetType() .GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance) .Where(p => typeof(INimbusConfiguration).IsAssignableFrom(p.PropertyType)) .Select(p => (INimbusConfiguration)p.GetValue(configuration)) .Do(container.RegisterPropertiesFromConfigurationObject) .Done(); }
public void RegisterWith(PoorMansIoC container) { container.Register(TypeProvider, typeof(ITypeProvider)); container.Register(DependencyResolver, typeof(IDependencyResolver)); container.Register(Logger, typeof(ILogger)); container.Register(Serializer, typeof(ISerializer)); container.Register(Compressor, typeof(ICompressor)); container.Register(Router, typeof(IRouter)); container.Register(DeliveryRetryStrategy, typeof(IDeliveryRetryStrategy)); container.RegisterType <PathFactory>(ComponentLifetime.SingleInstance, typeof(IPathFactory)); container.RegisterType <ReplyQueueNameSetting>(ComponentLifetime.SingleInstance); container.RegisterType <RequestResponseCorrelator>(ComponentLifetime.SingleInstance); container.RegisterType <CommandMessagePumpsFactory>(ComponentLifetime.SingleInstance); container.RegisterType <RequestMessagePumpsFactory>(ComponentLifetime.SingleInstance); container.RegisterType <ResponseMessagePumpFactory>(ComponentLifetime.SingleInstance); container.RegisterType <MulticastRequestMessagePumpsFactory>(ComponentLifetime.SingleInstance); container.RegisterType <MulticastEventMessagePumpsFactory>(ComponentLifetime.SingleInstance); container.RegisterType <CompetingEventMessagePumpsFactory>(ComponentLifetime.SingleInstance); container.RegisterType <SystemClock>(ComponentLifetime.SingleInstance, typeof(IClock)); container.RegisterType <DispatchContextManager>(ComponentLifetime.SingleInstance, typeof(IDispatchContextManager)); container.RegisterType <ResponseMessageDispatcher>(ComponentLifetime.SingleInstance); container.RegisterType <HandlerMapper>(ComponentLifetime.SingleInstance, typeof(IHandlerMapper)); container.RegisterType <MessageDispatcherFactory>(ComponentLifetime.SingleInstance, typeof(IMessageDispatcherFactory)); container.RegisterType <InboundInterceptorFactory>(ComponentLifetime.SingleInstance, typeof(IInboundInterceptorFactory)); container.RegisterType <OutboundInterceptorFactory>(ComponentLifetime.SingleInstance, typeof(IOutboundInterceptorFactory)); container.RegisterType <PropertyInjector>(ComponentLifetime.SingleInstance, typeof(IPropertyInjector), typeof(PropertyInjector)); container.RegisterType <NimbusMessageFactory>(ComponentLifetime.SingleInstance, typeof(INimbusMessageFactory)); container.RegisterType <BusCommandSender>(ComponentLifetime.SingleInstance, typeof(ICommandSender)); container.RegisterType <BusRequestSender>(ComponentLifetime.SingleInstance, typeof(IRequestSender)); container.RegisterType <BusMulticastRequestSender>(ComponentLifetime.SingleInstance, typeof(IMulticastRequestSender)); container.RegisterType <BusEventSender>(ComponentLifetime.SingleInstance, typeof(IEventSender)); container.RegisterType <KnownMessageTypeVerifier>(ComponentLifetime.SingleInstance, typeof(IKnownMessageTypeVerifier)); container.RegisterType <Heartbeat>(ComponentLifetime.SingleInstance, typeof(IHeartbeat)); container.RegisterType <Bus>(ComponentLifetime.SingleInstance); container.RegisterType <GlobalHandlerThrottle>(ComponentLifetime.SingleInstance, typeof(IGlobalHandlerThrottle)); container.RegisterType <FilterConditionProvider>(ComponentLifetime.SingleInstance, typeof(IFilterConditionProvider)); container.RegisterType <MessagePump>(ComponentLifetime.InstancePerDependency); container.RegisterType <DefaultRetry>(ComponentLifetime.InstancePerDependency, typeof(IRetry)); }
internal static Bus Build(BusBuilderConfiguration configuration) { var logger = configuration.Logger; logger.Debug("Constructing bus..."); var container = new PoorMansIoC(); RegisterPropertiesFromConfigurationObject(container, configuration); RegisterPropertiesFromConfigurationObject(container, configuration.LargeMessageStorageConfiguration); RegisterPropertiesFromConfigurationObject(container, configuration.Debugging); var namespaceManagerRoundRobin = new RoundRobin <NamespaceManager>( container.Resolve <ServerConnectionCountSetting>(), () => { var namespaceManager = NamespaceManager.CreateFromConnectionString(container.Resolve <ConnectionStringSetting>()); namespaceManager.Settings.OperationTimeout = TimeSpan.FromSeconds(120); return(namespaceManager); }, nsm => false, nsm => { }); container.Register <Func <NamespaceManager> >(c => namespaceManagerRoundRobin.GetNext); var messagingFactoryRoundRobin = new RoundRobin <MessagingFactory>( container.Resolve <ServerConnectionCountSetting>(), () => { var messagingFactory = MessagingFactory.CreateFromConnectionString(container.Resolve <ConnectionStringSetting>()); messagingFactory.PrefetchCount = container.Resolve <ConcurrentHandlerLimitSetting>(); return(messagingFactory); }, mf => mf.IsBorked(), mf => { }); container.Register <Func <MessagingFactory> >(c => messagingFactoryRoundRobin.GetNext); if (configuration.Debugging.RemoveAllExistingNamespaceElements) { var namespaceCleanser = container.Resolve <NamespaceCleanser>(); namespaceCleanser.RemoveAllExistingNamespaceElements().Wait(); } logger.Debug("Creating message pumps..."); var messagePumps = new MessagePumpsManager( container.Resolve <ResponseMessagePumpFactory>().Create(), container.Resolve <RequestMessagePumpsFactory>().CreateAll(), container.Resolve <CommandMessagePumpsFactory>().CreateAll(), container.Resolve <MulticastRequestMessagePumpsFactory>().CreateAll(), container.Resolve <MulticastEventMessagePumpsFactory>().CreateAll(), container.Resolve <CompetingEventMessagePumpsFactory>().CreateAll(), container.Resolve <INimbusTaskFactory>()); logger.Debug("Message pumps are all created."); var bus = new Bus(container.Resolve <ILogger>(), container.Resolve <ICommandSender>(), container.Resolve <IRequestSender>(), container.Resolve <IMulticastRequestSender>(), container.Resolve <IEventSender>(), messagePumps, container.Resolve <DeadLetterQueues>(), container.Resolve <INimbusTaskFactory>(), container.Resolve <IHeartbeat>()); bus.Starting += delegate { container.Resolve <AzureQueueManager>().WarmUp(); container.Resolve <PropertyInjector>().Bus = bus; }; bus.Disposing += delegate { container.Dispose(); }; logger.Info("Bus built. Job done!"); return(bus); }