/// <summary> /// Loads all message handler assemblies in the runtime directory /// and specifies that the handlers in the given 'order' are to /// run before all others and in the order specified. /// </summary> /// <param name="config">The <see cref="EndpointConfiguration" /> instance to apply the settings to.</param> /// <param name="handlerTypes">The handler types to execute first.</param> public static void ExecuteTheseHandlersFirst(this EndpointConfiguration config, IEnumerable <Type> handlerTypes) { Guard.AgainstNull(nameof(config), config); Guard.AgainstNull(nameof(handlerTypes), handlerTypes); List <Type> list; if (!config.Settings.TryGet("NServiceBus.ExecuteTheseHandlersFirst", out list)) { list = new List <Type>(); config.Settings.Set("NServiceBus.ExecuteTheseHandlersFirst", list); } foreach (var handlerType in handlerTypes) { if (!RegisterHandlersInOrder.IsMessageHandler(handlerType)) { throw new ArgumentException($"'{handlerType}' is not a handler type, ensure that all types derive from IHandleMessages"); } if (list.Contains(handlerType)) { throw new ArgumentException($"The order in which the type '{handlerType}' should be invoked was already specified by a previous call. A handler type can only specified once."); } list.Add(handlerType); } }
public void Simple_handler_should_be_classified_as_a_handler() { Assert.IsTrue(RegisterHandlersInOrder.IsMessageHandler(typeof(SimpleHandler))); }
public void Specific_generic_type_definition_handler_should_not_be_classified_as_a_handler() { Assert.IsTrue(RegisterHandlersInOrder.IsMessageHandler(typeof(GenericTypeDefinitionHandler <string>))); }
public void Generic_implemented_type_definition_handler_should_not_be_classified_as_a_handler() { Assert.IsTrue(RegisterHandlersInOrder.IsMessageHandler(typeof(GenericImplementedHandler))); }
public void Generic_type_definition_handler_should_not_be_classified_as_a_handler() { Assert.IsFalse(RegisterHandlersInOrder.IsMessageHandler(typeof(GenericTypeDefinitionHandler <>))); }
public void Interface_handler_should_not_be_classified_as_a_handler() { Assert.IsFalse(RegisterHandlersInOrder.IsMessageHandler(typeof(InterfaceHandler))); }
public void Not_implementing_IHandleMessages_should_not_be_classified_as_a_handler() { Assert.IsFalse(RegisterHandlersInOrder.IsMessageHandler(typeof(NotImplementingIHandleMessages))); }
public void Abstract_handler_should_not_be_classified_as_a_handler() { Assert.IsFalse(RegisterHandlersInOrder.IsMessageHandler(typeof(AbstractHandler))); }
public void Concrete_implementation_of_abstract_handler_should_be_classified_as_a_handler() { Assert.IsTrue(RegisterHandlersInOrder.IsMessageHandler(typeof(ConcreteImplementationOfAbstractHandler))); }