/// <summary> /// Configure by letting Bifrost discover anything that implements the discoverable configuration interfaces. /// </summary> /// <returns>Configuration object to continue configuration on.</returns> public static Configure DiscoverAndConfigure(IBootstrapConfiguration bootstrapConfiguration) { var bootstrapper = new Bootstrapper(); var bootstrapContainer = bootstrapper.BootstrapTypes(bootstrapConfiguration); var container = bootstrapContainer.BootstrapContainer(); bootstrapContainer.Get<IDefaultBindings>().Initialize(container); bootstrapContainer.Get<IDefaultConventions>().Initialize(container); var configure = With(container); configure.Initialize(); return configure; }
/// <summary> /// Bootstraps the application by discovering types. It will discover types using the given configuration /// and feed the types to all discovered implementations of <see cref="ICollectTypes"/>. /// </summary> /// <param name="bootstrapConfiguration">The bootstrap configuration to use.</param> /// <returns>An <see cref="IBootstrapContainer"/> which can be used to create simple types /// and finally initialize the real container.</returns> public IBootstrapContainer BootstrapTypes(IBootstrapConfiguration bootstrapConfiguration) { var assembliesConfiguration = bootstrapConfiguration.AssembliesConfiguration; var assemblySpecifiers = new AssemblySpecifiers(assembliesConfiguration); var typeCollector = new TypeCollector(); var assemblyProvider = new AssemblyProvider( bootstrapConfiguration.AssemblyProviders, assemblySpecifiers, new AssemblyFilters(assembliesConfiguration), new TypeFilters(bootstrapConfiguration.TypesConfiguration), typeCollector); typeCollector.RegisterForAutoBind(assemblyProvider); return typeCollector; }
/// <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); } }