/// <summary> /// Scans the given types for instances of the requested interface /// </summary> /// <param name="typesToScan">Types to scan</param> /// <param name="handlerTypeToFind">Handler type to find</param> /// <param name="objectBuilder">Object builder to register the types with</param> /// <returns>Types found</returns> private static Dictionary <Type, HashSet <Type> > ScanForTypes(IEnumerable <Type> typesToScan, Type handlerTypeToFind, IObjectBuilder objectBuilder) { Dictionary <Type, HashSet <Type> > results = new Dictionary <Type, HashSet <Type> >(); var handlerTypes = typesToScan.Where(x => x.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == handlerTypeToFind)); foreach (var handlerType in handlerTypes) { foreach (var handlerTypeType in handlerType.GetInterfaces().Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == handlerTypeToFind)) { Type messageType = handlerTypeType.GenericTypeArguments[0]; if (!results.ContainsKey(messageType)) { results[messageType] = new HashSet <Type>(); } results[messageType].Add(handlerType); } objectBuilder.RegisterType(handlerType, handlerType); } return(results); }