예제 #1
0
        /// <summary>
        /// Scans the given types for types that are message handlers
        /// then uses the Configurer to configure them into the container as single call components,
        /// finally passing them to the bus as its MessageHandlerTypes.
        /// </summary>
        /// <param name="types"></param>
        /// <returns></returns>
        ConfigUnicastBus ConfigureMessageHandlersIn(IEnumerable <Type> types)
        {
            var handlerRegistry = new MessageHandlerRegistry();
            var handlers        = new List <Type>();

            foreach (var t in types.Where(IsMessageHandler))
            {
                Configurer.ConfigureComponent(t, DependencyLifecycle.InstancePerUnitOfWork);
                handlerRegistry.RegisterHandler(t);
                handlers.Add(t);
            }

            Configurer.RegisterSingleton <IMessageHandlerRegistry>(handlerRegistry);

            var availableDispatcherFactories = TypesToScan
                                               .Where(
                factory =>
                !factory.IsInterface && typeof(IMessageDispatcherFactory).IsAssignableFrom(factory))
                                               .ToList();

            var dispatcherMappings = GetDispatcherFactories(handlers, availableDispatcherFactories);

            //configure the message dispatcher for each handler
            busConfig.ConfigureProperty(b => b.MessageDispatcherMappings, dispatcherMappings);
            Configurer.ConfigureProperty <InvokeHandlersBehavior>(b => b.MessageDispatcherMappings, dispatcherMappings);

            availableDispatcherFactories.ToList().ForEach(factory => Configurer.ConfigureComponent(factory, DependencyLifecycle.InstancePerUnitOfWork));

            return(this);
        }
예제 #2
0
        void ConfigureMessageRegistry(List <Type> knownMessages)
        {
            var messageRegistry = new MessageMetadataRegistry
            {
                DefaultToNonPersistentMessages = !SettingsHolder.Get <bool>("Endpoint.DurableMessages")
            };

            knownMessages.ForEach(messageRegistry.RegisterMessageType);

            Configurer.RegisterSingleton <MessageMetadataRegistry>(messageRegistry);

            if (!Logger.IsInfoEnabled)
            {
                return;
            }

            var messageDefinitions = messageRegistry.GetAllMessages().ToList();

            Logger.InfoFormat("Number of messages found: {0}", messageDefinitions.Count());

            if (!Logger.IsDebugEnabled)
            {
                return;
            }


            Logger.DebugFormat("Message definitions: \n {0}", string.Concat(messageDefinitions.Select(md => md.ToString() + "\n")));
        }
예제 #3
0
        void RegisterMessageOwnersAndBusAddress(IEnumerable <Type> knownMessages)
        {
            var unicastConfig = GetConfigSection <UnicastBusConfig>();
            var router        = new StaticMessageRouter(knownMessages);

            Configurer.RegisterSingleton <IRouteMessages>(router);

            if (unicastConfig == null)
            {
                return;
            }
            if (!string.IsNullOrWhiteSpace(unicastConfig.ForwardReceivedMessagesTo))
            {
                var forwardAddress = Address.Parse(unicastConfig.ForwardReceivedMessagesTo);
                busConfig.ConfigureProperty(b => b.ForwardReceivedMessagesTo, forwardAddress);
            }
            busConfig.ConfigureProperty(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages);

            var messageEndpointMappings = unicastConfig.MessageEndpointMappings.Cast <MessageEndpointMapping>()
                                          .OrderByDescending(m => m)
                                          .ToList();

            foreach (var mapping in messageEndpointMappings)
            {
                mapping.Configure((messageType, address) =>
                {
                    if (!MessageConventionExtensions.IsMessageType(messageType))
                    {
                        return;
                    }

                    router.RegisterRoute(messageType, address);
                });
            }
        }
예제 #4
0
        public ConfigSimpleCqrs UseNsbEventBus()
        {
            var eventBus = new NsbEventBus();

            ServiceLocator.Register <IEventBus>(eventBus);
            Configurer.RegisterSingleton <IEventBus>(eventBus);

            return(this);
        }
예제 #5
0
        public ConfigSimpleCqrs UseLocalCommandBus()
        {
            var commandBus = ServiceLocator.Resolve <LocalCommandBus>();

            ServiceLocator.Register <ICommandBus>(commandBus);
            Configurer.RegisterSingleton <ICommandBus>(commandBus);

            return(this);
        }
예제 #6
0
        public ConfigSimpleCqrs UseNsbCommandBus()
        {
            var config     = new ConfigCommandBus(runtime);
            var commandBus = config.Configure(this);

            ServiceLocator.Register <ICommandBus>(commandBus);
            Configurer.RegisterSingleton <ICommandBus>(commandBus);

            return(this);
        }
예제 #7
0
        public void Configure(Configure config)
        {
            Configurer = config.Configurer;
            Builder    = config.Builder;

            runtime.Start();

            ServiceLocator = runtime.ServiceLocator;
            ServiceLocator.Register(() => Builder.Build <IBus>());
            Configurer.RegisterSingleton <ISimpleCqrsRuntime>(runtime);
        }
예제 #8
0
        public ConfigSimpleCqrs SubscribeForDomainEvents()
        {
            var typeCatalog = ServiceLocator.Resolve <ITypeCatalog>();
            var domainEventHandlerFactory = ServiceLocator.Resolve <IDomainEventHandlerFactory>();
            var domainEventTypes          = typeCatalog.GetGenericInterfaceImplementations(typeof(IHandleDomainEvents <>));

            var eventBus = new NsbLocalEventBus(domainEventTypes, domainEventHandlerFactory);

            Configurer.RegisterSingleton <IEventBus>(eventBus);

            var configEventBus = new ConfigEventBus();

            configEventBus.Configure(this, runtime);

            return(this);
        }