Esempio n. 1
0
        /// <summary>
        /// Register handlers into the Unity container.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="container">The Unity container.</param>
        public static void RegisterHandlers(this ProcessorConfiguration configuration, IUnityContainer container)
        {
            if (configuration == null)
            {
                throw Error.ArgumentNull("configuration");
            }

            ICommandHandlerDescriptorProvider            commandDescriptorProvider = configuration.Services.GetCommandHandlerDescriptorProvider();
            IDictionary <Type, CommandHandlerDescriptor> commandDescriptorsMapping = commandDescriptorProvider.GetHandlerMapping();

            foreach (KeyValuePair <Type, CommandHandlerDescriptor> description in commandDescriptorsMapping)
            {
                LifetimeManager lifetime = GetLifetimeManager(description.Value.Lifetime);
                container.RegisterType(description.Value.HandlerType, lifetime);
            }

            IEventHandlerDescriptorProvider             eventDescriptorProvider = configuration.Services.GetEventHandlerDescriptorProvider();
            IDictionary <Type, EventHandlersDescriptor> eventDescriptorsMapping = eventDescriptorProvider.GetHandlerMapping();

            foreach (KeyValuePair <Type, EventHandlersDescriptor> descriptor in eventDescriptorsMapping)
            {
                foreach (EventHandlerDescriptor eventHandlerDescriptor in descriptor.Value.EventHandlerDescriptors)
                {
                    LifetimeManager lifetime = GetLifetimeManager(eventHandlerDescriptor.Lifetime);
                    container.RegisterType(eventHandlerDescriptor.HandlerType, lifetime);
                }
            }
        }
Esempio n. 2
0
        private static void RegisterCommandHandlerCore <TCommand>(ProcessorConfiguration config, Func <TCommand, Task> handler) where TCommand : ICommand
        {
            Contract.Requires(config != null);

            ICommandHandlerDescriptorProvider            descriptorProvider = config.Services.GetCommandHandlerDescriptorProvider();
            IDictionary <Type, CommandHandlerDescriptor> mapping            = descriptorProvider.GetHandlerMapping();

            mapping.Add(typeof(TCommand), new CommandHandlerDescriptor <TCommand>(config, typeof(TCommand), handler));
        }