void Inspect(Assembly assembly, ICollection <IComponentRegistration> componentList, ICollection <IModule> modules) { var types = CoreExtensions.GetInspectableTypes(assembly); foreach (var type in types) { foreach (var attribute in type.GetAttributes <IComponentMetadata>(true)) { componentList.Add(attribute.GetComponentInfo(type)); } } foreach (var type in types) { if (!ModuleType.IsAssignableFrom(type) || type.IsAbstract || type.IsInterface) { continue; } var singleton = type.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); if (singleton != null) { modules.Add((IModule)singleton.GetValue(null, null)); } else { modules.Add((IModule)Activator.CreateInstance(type)); } } log.Info("Assembly {0} inspected.", assembly); }
void RegisterItemsWithSubjects(IRegistry registry, Assembly assembly) { var matches = from type in CoreExtensions.GetInspectableTypes(assembly) let service = type.FindInterfaceThatCloses(typeof(IHaveSubject <>)) where service != null select new PerRequest { Service = service, Implementation = type, Name = nameInstances ? type.AssemblyQualifiedName : null }; registry.Register(matches.OfType <IComponentRegistration>()); }