/// <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> /// Creates an instance of all types implementing the `IComponentResolverBootstrap` interface and calls the `Resolve` /// method. /// </summary> /// <param name="resolver">The `IComponentResolver` instance to resolve dependencies from.</param> /// <param name="resolverConfiguration">The `IComponentResolverConfiguration` instance that contains the registry configuration.</param> /// <param name="bootstrapConfiguration">The `IBootstrapConfiguration` instance that contains the bootstrapping configuration.</param> public static void ResolverBoostrap(IComponentResolver resolver, IComponentResolverConfiguration resolverConfiguration, IBootstrapConfiguration bootstrapConfiguration) { Guard.AgainstNull(resolver, "resolver"); Guard.AgainstNull(resolverConfiguration, nameof(resolverConfiguration)); var reflectionService = new ReflectionService(); foreach (var assembly in bootstrapConfiguration.Assemblies) { foreach (var type in reflectionService.GetTypes <IComponentResolverBootstrap>(assembly)) { type.AssertDefaultConstructor(string.Format(InfrastructureResources.DefaultConstructorRequired, "IComponentResolverBootstrap", type.FullName)); ((IComponentResolverBootstrap)Activator.CreateInstance(type)).Resolve(resolver); } } foreach (var component in resolverConfiguration.Components) { resolver.Resolve(component.DependencyType); } }