/// <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; }
public static Configure DiscoverAndConfigure(Action<AssembliesConfigurationBuilder> assembliesConfigurationBuilderCallback = null, IEnumerable<ICanProvideAssemblies> additionalAssemblyProviders = null) #endif { IContractToImplementorsMap contractToImplementorsMap; var assembliesConfigurationBuilder = BuildAssembliesConfigurationIfCallbackDefined(assembliesConfigurationBuilderCallback); contractToImplementorsMap = new ContractToImplementorsMap(); #if (SILVERLIGHT) var assemblyProvider = new AssemblyProvider(); var assembliesConfiguration = new AssembliesConfiguration(assembliesConfigurationBuilder.RuleBuilder); #else var executingAssembly = Assembly.GetExecutingAssembly(); contractToImplementorsMap.Feed(executingAssembly.GetTypes()); var assemblySpecifiers = new AssemblySpecifiers(contractToImplementorsMap, new TypeFinder(), assembliesConfigurationBuilder.RuleBuilder); assemblySpecifiers.SpecifyUsingSpecifiersFrom(executingAssembly); var assemblyProviders = new List<ICanProvideAssemblies> { new AppDomainAssemblyProvider(), new FileSystemAssemblyProvider(new FileSystem()) }; if (additionalAssemblyProviders != null) assemblyProviders.AddRange(additionalAssemblyProviders); var assembliesConfiguration = new AssembliesConfiguration(assembliesConfigurationBuilder.RuleBuilder); var assemblyProvider = new AssemblyProvider( assemblyProviders, new AssemblyFilters(assembliesConfiguration), new AssemblyUtility(), assemblySpecifiers, contractToImplementorsMap); #endif var assemblies = assemblyProvider.GetAll(); var canCreateContainerType = DiscoverCanCreateContainerType(assemblies); ThrowIfCanCreateContainerNotFound(canCreateContainerType); ThrowIfCanCreateContainerDoesNotHaveDefaultConstructor(canCreateContainerType); var canCreateContainerInstance = Activator.CreateInstance(canCreateContainerType) as ICanCreateContainer; var container = canCreateContainerInstance.CreateContainer(); var configure = With(container, BindingLifecycle.Transient, assembliesConfiguration, assemblyProvider, contractToImplementorsMap); configure.EntryAssembly = canCreateContainerType.Assembly; configure.Initialize(); return configure; }