/// <summary> /// Creates an instance of all types implementing the `IComponentRegistryBootstrap` interface and calls the `Register` /// method. /// </summary> /// <param name="registry">The `IComponentRegistry` instance to pass register the components in.</param> /// <param name="registryConfiguration">The `IComponentRegistryConfiguration` instance that contains the registry configuration.</param> /// <param name="bootstrapConfiguration">The `IBootstrapConfiguration` instance that contains the bootstrapping configuration.</param> public static void RegistryBoostrap(this IComponentRegistry registry, IComponentRegistryConfiguration registryConfiguration, IBootstrapConfiguration bootstrapConfiguration) { Guard.AgainstNull(registry, "registry"); var completed = new List <Type>(); var reflectionService = new ReflectionService(); foreach (var assembly in bootstrapConfiguration.Assemblies) { foreach (var type in reflectionService.GetTypes <IComponentRegistryBootstrap>(assembly)) { if (completed.Contains(type)) { continue; } type.AssertDefaultConstructor(string.Format(InfrastructureResources.DefaultConstructorRequired, "IComponentRegistryBootstrap", type.FullName)); ((IComponentRegistryBootstrap)Activator.CreateInstance(type)).Register(registry); completed.Add(type); } } foreach (var component in registryConfiguration.Components) { registry.Register(component.DependencyType, component.ImplementationType, component.Lifestyle); } foreach (var collection in registryConfiguration.Collections) { registry.RegisterCollection(collection.DependencyType, collection.ImplementationTypes, collection.Lifestyle); } }
/// <summary> /// Attempts to register all components specified in the given `IComponentRegistryConfiguration` instance. /// </summary> /// <param name="registry">The `IComponentRegistry` instance to register the mapping against.</param> /// <param name="registryConfiguration"> /// The `IComponentRegistryConfiguration` instance that contains the registry /// configuration. /// </param> public static void AttemptRegisterConfiguration(this IComponentRegistry registry, IComponentRegistryConfiguration registryConfiguration) { Guard.AgainstNull(registry, nameof(registry)); foreach (var component in registryConfiguration.Components) { registry.Register(component.DependencyType, component.ImplementationType, component.Lifestyle); } foreach (var collection in registryConfiguration.Collections) { registry.RegisterCollection(collection.DependencyType, collection.ImplementationTypes, collection.Lifestyle); } }