コード例 #1
0
        /// <summary>
        /// Uses reflection to add handling rules for every implemented <see cref="IMessageHandler{TContent}"/>
        /// interface.
        /// </summary>
        /// <remarks>
        /// <para>A handling rule will be added for implemented <see cref="IMessageHandler{TContent}"/> interface
        /// of <typeparamref name="THandler"/> according to the following convention:</para>
        /// <list type="bullet">
        /// <item>The name pattern will be an exact match of the <see cref="MessageName"/> returned by the
        /// <see cref="IMessageNamingService"/> in the specified <paramref name="configuration"/></item>
        /// <item>The handling function will retrieve an instance of the handler object using the supplied
        /// <paramref name="handlerFactory"/> and invoke the appropriate <see cref="IMessageHandler{TContent}.HandleMessage"/>
        /// method (via reflection)</item>
        /// <item>The designated queue name will be a hash derived from the full names of the <typeparamref name="THandler"/>
        /// type and the type of message that is handled</item>
        /// </list>
        /// </remarks>
        /// <typeparam name="THandler">The type of message handler</typeparam>
        /// <param name="configuration">The Platibus configuration to which the handling rules will be added</param>
        /// <param name="handlerFactory">(Optional) A factory method for getting an instance of the handler (may
        /// return a singleton or scoped handler instance).  If no factory method is specified, then the
        /// default constructor will be used.</param>
        /// <param name="queueNameFactory">(Optional) A factory method that will return an appropriate queue
        /// name for each combination of handler type and message type</param>
        /// <param name="queueOptions">(Optional) Options for how queued messages for the handler
        /// should be processed</param>
        public static void AddHandlingRules <THandler>(this PlatibusConfiguration configuration,
                                                       Func <THandler> handlerFactory = null, QueueNameFactory queueNameFactory = null,
                                                       QueueOptions queueOptions      = null)
        {
            Func <object> factory = null;

            if (handlerFactory != null)
            {
                factory = () => handlerFactory();
            }
            configuration.AddHandlingRulesForType(typeof(THandler), factory, queueNameFactory, queueOptions);
        }
コード例 #2
0
 /// <summary>
 /// Uses reflection to add handling rules for every implemented <see cref="IMessageHandler{TContent}"/>
 /// interface on the specified <paramref name="handler"/> instance.
 /// </summary>
 /// <remarks>
 /// <para>A handling rule will be added for implemented <see cref="IMessageHandler{TContent}"/> interface
 /// of <typeparamref name="THandler"/> according to the following convention:</para>
 /// <list type="bullet">
 /// <item>The name pattern will be an exact match of the <see cref="MessageName"/> returned by the
 /// <see cref="IMessageNamingService"/> in the specified <paramref name="configuration"/></item>
 /// <item>The handling function will rinvoke the appropriate <see cref="IMessageHandler{TContent}.HandleMessage"/>
 /// method (via reflection) on the specified <paramref name="handler"/> instance</item>
 /// <item>The designated queue name will be a hash derived from the full names of the <typeparamref name="THandler"/>
 /// type and the type of message that is handled</item>
 /// </list>
 /// </remarks>
 /// <typeparam name="THandler">The type of message handler</typeparam>
 /// <param name="configuration">The Platibus configuration to which the handling rules will be added</param>
 /// <param name="handler">The singleton handler instance</param>
 /// <param name="queueNameFactory">(Optional) A factory method that will return an appropriate queue
 /// name for each combination of handler type and message type</param>
 /// <param name="queueOptions">(Optional) Options for how queued messages for the handler
 /// should be processed</param>
 public static void AddHandlingRules <THandler>(this PlatibusConfiguration configuration,
                                                THandler handler, QueueNameFactory queueNameFactory = null,
                                                QueueOptions queueOptions = null)
 {
     configuration.AddHandlingRulesForType(typeof(THandler), () => handler, queueNameFactory, queueOptions);
 }