示例#1
0
        // -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
        // 1. General registration (Action without IServiceLocator)
        // -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

        /// <summary>
        /// Register named general delegate <see cref="Action{Object}"/> subscribed on list of messages, with specified DispatchMode
        /// </summary>
        /// <param name="action">Delegate instance</param>
        /// <param name="uniqueName">Unique name that can be used to identify this handler</param>
        /// <param name="mode">Dispatching mode. Default value is DispatchMode.InterfaceDescendants</param>
        /// <param name="messageTypes">List of message types this handler subscribed on</param>
        public static DispatcherConfiguration RegisterHandler(this DispatcherConfiguration configuration, Action <Object> action, String uniqueName, DispatchMode mode, params Type[] messageTypes)
        {
            IHandler handler = new DelegateHandler(action, uniqueName, mode, messageTypes);

            configuration.Builder.Register(handler);
            return(configuration);
        }
示例#2
0
        /// <summary>
        /// Factory method
        /// </summary>
        public static Dispatcher Create(Func <DispatcherConfiguration, DispatcherConfiguration> configurationAction)
        {
            var config = new DispatcherConfiguration();

            configurationAction(config);
            return(new Dispatcher(config));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public Dispatcher(DispatcherConfiguration configuration)
        {
            if (configuration.ServiceLocator == null)
                throw new ArgumentException("Service Locator is not registered for distributor.");

            _registry = configuration.Builder.BuildHandlerRegistry();
            _serviceLocator = configuration.ServiceLocator;

            /*
            if (configuration.DispatcherHandlerRegistry == null)
                throw new ArgumentException("Dispatcher Handler Registry is null in distributor.");

            
            _registry = configuration.DispatcherHandlerRegistry;
            _maxRetries = configuration.MaxRetries;

            // order handlers 
            _registry.InsureOrderOfHandlers(configuration.Order);*/
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public Dispatcher(DispatcherConfiguration configuration)
        {
            if (configuration.ServiceLocator == null)
            {
                throw new ArgumentException("Service Locator is not registered for distributor.");
            }

            _registry       = configuration.Builder.BuildHandlerRegistry();
            _serviceLocator = configuration.ServiceLocator;

            /*
             * if (configuration.DispatcherHandlerRegistry == null)
             *  throw new ArgumentException("Dispatcher Handler Registry is null in distributor.");
             *
             *
             * _registry = configuration.DispatcherHandlerRegistry;
             * _maxRetries = configuration.MaxRetries;
             *
             * // order handlers
             * _registry.InsureOrderOfHandlers(configuration.Order);*/
        }
示例#5
0
 /// <summary>
 /// Register handler that subscribed to three messages.
 /// </summary>
 /// <typeparam name="TMessage1">First message type this handler subscribed to</typeparam>
 /// <typeparam name="TMessage2">Second message type this handler subscribed to</typeparam>
 /// <typeparam name="TMessage3">Third message type this handler subscribed to</typeparam>
 /// <param name="action">Delegate instance</param>
 public static DispatcherConfiguration RegisterHandler <TMessage1, TMessage2, TMessage3>(this DispatcherConfiguration configuration, Action <Object, IServiceLocator> action, String uniqueName = null, DispatchMode dispatchMode = DispatchMode.InterfaceDescendants)
 {
     return(RegisterHandler(configuration, action, uniqueName, dispatchMode, new[] { typeof(TMessage1), typeof(TMessage2), typeof(TMessage3) }));
 }
示例#6
0
 /// <summary>
 /// TAssemblyType can be different, then was used in RegisterAssemblyHandlers
 /// </summary>
 public static DispatcherConfiguration UnregisterAsseblyHandlers <TAssemblyType>(this DispatcherConfiguration configuration)
 {
     return(configuration);
 }
示例#7
0
 public static DispatcherConfiguration UnregisterAssemblyHandlers(this DispatcherConfiguration configuration, Assembly assembly)
 {
     return(configuration);
 }
 /// <summary>
 /// Register single handler. This is a way to register custom handlers.
 /// </summary>
 public static DispatcherConfiguration RegisterHandler(this DispatcherConfiguration configuration, IHandler handler)
 {
     configuration.Builder.Register(handler);
     return(configuration);
 }
示例#9
0
 /// <summary>
 /// Register delegate as handler, with list of message types this handler subscribed to.
 /// </summary>
 /// <param name="action">Delegate instance</param>
 /// <param name="messageTypes">List of message types this handler subscribed on</param>
 public static DispatcherConfiguration RegisterHandler(this DispatcherConfiguration configuration, Action <Object> action, params Type[] messageTypes)
 {
     return(RegisterHandler(configuration, action, null, messageTypes));
 }
 public static DispatcherConfiguration InsureMessageHandlingOrder <TMessage, THandler1, THandler2, THandler3>(this DispatcherConfiguration configuration)
 {
     return(configuration);
 }
 public static DispatcherConfiguration SetNumberOfRetries(this DispatcherConfiguration configuration, Int32 numberOfRetries)
 {
     configuration.NumberOfRetries = numberOfRetries;
     return(configuration);
 }
 public static DispatcherConfiguration SetUnityContainer(this DispatcherConfiguration configuration, IUnityContainer container)
 {
     configuration.ServiceLocator = new UnityServiceLocator(container);
     return(configuration);
 }
 public static DispatcherConfiguration SetOrder(this DispatcherConfiguration configuration, params Type[] types)
 {
     configuration.Order = types.ToList();
     return(configuration);
 }
/*        public static DispatcherConfiguration AddHandlers(this DispatcherConfiguration configuration, Assembly assembly, String[] namespaces)
 *      {
 *          configuration.DispatcherHandlerRegistry.Register(assembly, namespaces);
 *          return configuration;
 *      }
 *
 *      public static DispatcherConfiguration AddInterceptor(this DispatcherConfiguration configuration, Type interceptor)
 *      {
 *          configuration.DispatcherHandlerRegistry.AddInterceptor(interceptor);
 *          return configuration;
 *      }*/

        /*
         * public static DispatcherConfiguration AddHandlers(this DispatcherConfiguration configuration, Assembly assembly)
         * {
         *  return AddHandlers(configuration, assembly, new string[] { });
         * }*/

        public static DispatcherConfiguration SetHandlerMarkerInterface(this DispatcherConfiguration configuration, Type markerInterface)
        {
            configuration.MessageHandlerMarkerInterface = markerInterface;
            return(configuration);
        }
 public static DispatcherConfiguration SetServiceLocator(this DispatcherConfiguration configuration, IServiceLocator container)
 {
     configuration.ServiceLocator = container;
     return(configuration);
 }
示例#16
0
 /// <summary>
 /// Register named general delegate <see cref="Action{Object}"/> subscribed on list of messages
 /// </summary>
 /// <param name="action">Delegate instance</param>
 /// <param name="uniqueName">Unique name that can be used to identify this handler</param>
 /// <param name="messageTypes">List of message types this handler subscribed on</param>
 public static DispatcherConfiguration RegisterHandler(this DispatcherConfiguration configuration, Action <Object> action, String uniqueName, params Type[] messageTypes)
 {
     return(RegisterHandler(configuration, action, uniqueName, DispatchMode.InterfaceDescendants, messageTypes));
 }
 public static DispatcherConfiguration InsureHandlingOrder <THandler1, THandler2, THandler3, THandler4, THandler5>(this DispatcherConfiguration configuration)
 {
     return(configuration);
 }
示例#18
0
        // -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
        // 3. Generic registration (Action with IServiceLocator)
        // -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

        /// <summary>
        /// Register named delegate that subscribed to single message TMessage with specified DispatchMode.
        /// </summary>
        /// <typeparam name="TMessage">Message type this handler subscribed to</typeparam>
        /// <param name="action">Delegate instance</param>
        public static DispatcherConfiguration RegisterHandler <TMessage>(this DispatcherConfiguration configuration, Action <TMessage> action, String uniqueName = null, DispatchMode dispatchMode = DispatchMode.InterfaceDescendants)
        {
            return(RegisterHandler(configuration, m => action((TMessage)m), uniqueName, dispatchMode, new[] { typeof(TMessage) }));
        }
 public static DispatcherConfiguration InsureHandlingOrder(this DispatcherConfiguration configuration, params Object[] handlersKeys)
 {
     return(configuration);
 }
示例#20
0
 /// <summary>
 /// Factory method
 /// </summary>
 public static Dispatcher Create(Func<DispatcherConfiguration, DispatcherConfiguration> configurationAction)
 {
     var config = new DispatcherConfiguration();
     configurationAction(config);
     return new Dispatcher(config);
 }
 public static DispatcherConfiguration InsureMessageHandlingOrder(this DispatcherConfiguration configuration, Type messageType, params Type[] handlers)
 {
     return(configuration);
 }