internal void InternalRegisterMessageHandlers(Assembly assembly, IMessageHandlerConvention messageHandlerConvention) { Condition.Requires(assembly, "assembly").IsNotNull(); Condition.Requires(messageHandlerConvention, "messageHandlerLocator").IsNotNull(); Logger.DebugFormat("Scanning assembly '{0}' for message handlers.", assembly); Logger.DebugFormat("Using message handler convention '{0}'.", messageHandlerConvention); // Go through all types and all their methods looking for message handlers foreach (Type handler in assembly.GetTypes()) { foreach (MethodInfo method in handler.GetMethods()) { // Only test single-parameter methods for handlers ParameterInfo[] parameters = method.GetParameters(); if (parameters.Length == 1) { Type baseType = parameters[0].ParameterType; if (messageHandlerConvention.IsMessageHandler(method, baseType)) { // Go through all other messages that inherit from the handlers message parameter foreach (Type messageType in GetAllInheritedClasses(baseType)) { Logger.DebugFormat("Register message handler '{0}' on '{1}' for message type '{2}'.", method.Name, method.DeclaringType, messageType); MessageHandlerRegistration registration = new MessageHandlerRegistration(messageType, method); MessageHandlers.Add(registration); if (!MessageHandlerIndex.ContainsKey(messageType)) { MessageHandlerIndex.Add(messageType, new List <MessageHandlerRegistration>()); } MessageHandlerIndex[messageType].Add(registration); if (!ObjectContainer.HasComponent(method.DeclaringType)) { ObjectContainer.AddComponent(method.DeclaringType, method.DeclaringType); } } } } } } }