/// <summary> /// Creates dependent registrations from given discoveredAssemblies /// </summary> public virtual ICollection <DependentRegistration> CreateDependentRegistrations(IEnumerable <Assembly> assemblies) { var assemblyList = assemblies.ToList(); var readonlyAssemblies = new ReadOnlyCollection <Assembly>(assemblyList); var registrations = readonlyAssemblies .SelectMany(GetExportedTypes) .SelectMany(ConvertToDependentRegistrations) .ToList(); var discoveredRegistrations = new ReadOnlyCollection <DependentRegistration>(registrations.OfType <DependentRegistration>().ToList()); var configureExpression = new DependencyConfigurationExpression(readonlyAssemblies); var externals = BuildExternalRegistrations(registrations, configureExpression); return(discoveredRegistrations.Union(externals).ToList()); }
/// <summary> /// Builds a configurationexression to discover external dependencies /// </summary> /// <param name="attributes"></param> /// <param name="configurationExpression"></param> /// <returns></returns> protected virtual IEnumerable <DependentRegistration> BuildExternalRegistrations(ICollection <AttributeDependentBase> attributes, DependencyConfigurationExpression configurationExpression) { const BindingFlags flags = BindingFlags.Public | BindingFlags.Static; foreach (var external in attributes.OfType <DependencyConfigurationRegistration>()) { try { var info = external.Implementation.GetTypeInfo() .GetMethod(external.Configurator.MethodName, flags); // ReSharper disable once PossibleNullReferenceException info.Invoke(null, new object[] { configurationExpression }); } catch (Exception e) { ExceptionCollector.AddException(new Exception($"Failed to configure {external.Implementation.FullName}!", e)); } } return(configurationExpression.Build()); }