// - - - - - - - - - - - - - - - - - - - - - - - - - - - // 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="configuration"></param> /// <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); }
/// <summary> /// Factory method /// </summary> public static Dispatcher Create(Func <DispatcherConfiguration, DispatcherConfiguration> configurationAction) { var config = new DispatcherConfiguration(); configurationAction(config); return(new Dispatcher(config)); }
/// <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="configuration"></param> /// <param name="action">Delegate instance</param> /// <param name="uniqueName"></param> /// <param name="dispatchMode"></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) })); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - // 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="configuration"></param> /// <param name="action">Delegate instance</param> /// <param name="uniqueName"></param> /// <param name="dispatchMode"></param> public static DispatcherConfiguration RegisterHandler <TMessage>(this DispatcherConfiguration configuration, Action <TMessage, IServiceLocator> action, string uniqueName = null, DispatchMode dispatchMode = DispatchMode.InterfaceDescendants) { return(RegisterHandler(configuration, (m, s) => action((TMessage)m, s), uniqueName, dispatchMode, new[] { typeof(TMessage) })); }
public static DispatcherConfiguration SetOrder(this DispatcherConfiguration configuration, params Type[] types) { configuration.Order = types.ToList(); return(configuration); }
public static DispatcherConfiguration SetHandlerMarkerInterface(this DispatcherConfiguration configuration, Type markerInterface) { configuration.MessageHandlerMarkerInterface = markerInterface; 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); }
public static DispatcherConfiguration RegisterAssemblyHandlers(this DispatcherConfiguration configuration, Assembly assembly) { return(configuration); }
public static DispatcherConfiguration InsureMessageHandlingOrder(this DispatcherConfiguration configuration, Type messageType, params Type[] handlers) { return(configuration); }
public static DispatcherConfiguration InsureHandlingOrder(this DispatcherConfiguration configuration, params object[] handlersKeys) { return(configuration); }
public static DispatcherConfiguration InsureHandlingOrder <THandler1, THandler2, THandler3, THandler4, THandler5>(this DispatcherConfiguration configuration) { return(configuration); }
public static DispatcherConfiguration InsureMessageHandlingOrder <TMessage, THandler1, THandler2, THandler3>(this DispatcherConfiguration configuration) { return(configuration); }
public static DispatcherConfiguration SetNumberOfRetries(this DispatcherConfiguration configuration, int numberOfRetries) { configuration.NumberOfRetries = numberOfRetries; return(configuration); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Object"/> class. /// </summary> public Dispatcher(DispatcherConfiguration configuration) { _registry = configuration.Builder.BuildHandlerRegistry(); _serviceLocator = configuration.ServiceLocator ?? throw new ArgumentException("Service Locator is not registered for distributor."); }
/// <summary> /// Register named general delegate <see cref="Action{Object}"/> subscribed on list of messages /// </summary> /// <param name="configuration"></param> /// <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 SetServiceLocator(this DispatcherConfiguration configuration, IServiceLocator container) { configuration.ServiceLocator = container; return(configuration); }
/// <summary> /// Register delegate as handler, with list of message types this handler subscribed to. /// </summary> /// <param name="configuration"></param> /// <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)); }
/// <summary> /// TAssemblyType can be different, then was used in RegisterAssemblyHandlers /// </summary> public static DispatcherConfiguration UnregisterAsseblyHandlers <TAssemblyType>(this DispatcherConfiguration configuration) { return(configuration); }