/// <summary> /// Checks whether the given bootstrap service type is available in container /// and throws an exception otherwise. /// </summary> /// <typeparam name="T">Type of bootstrap service to check.</typeparam> void CheckBootstrapService <T>() where T : class { var bootstrapService = BootstrapServices.Get <T>(); if (bootstrapService == null) { throw new InvalidOperationException("No " + typeof(T).Name + " implementation available."); } }
/// <summary> /// Initializes all components and service information. /// </summary> public void Load() { if (_isLoaded) { // Already loaded // TODO Throw an exception? return; } // Ensure we have implementations for all essential bootstrap services CheckBootstrapService <ILogger>(); CheckBootstrapService <IComponentAssemblyProvider>(); CheckBootstrapService <IRegistration>(); CheckBootstrapService <IMetaInfoContainer>(); var logger = BootstrapServices.GetLogger(); // Get and/or load assemblies that we want to use var assemblies = BootstrapServices.GetComponentAssemblyProvider().GetAssemblies(); // Collect metadata var registration = BootstrapServices.GetRegistration(); registration.LoadComponentData(assemblies); var metaInfoContainer = BootstrapServices.GetMetaInfoContainer(); metaInfoContainer.ComponentInfos = registration.ComponentInfos; metaInfoContainer.ServiceInfos = registration.ServiceInfos; metaInfoContainer.Substitutions = registration.Substitutions; metaInfoContainer.ServiceLists = registration.ServiceLists; // Initialize all lifecycles foreach (var serviceInfoMapping in metaInfoContainer.ServiceInfos) { serviceInfoMapping.Value.Lifecycle.Prepare( new InitializationData(this, serviceInfoMapping.Value), logger); serviceInfoMapping.Value.Lifecycle.InitialActivation(); } _isLoaded = true; }