ServiceProvider DoCreateAutomaticServices(SimpleServiceContainer?startupServices, IStObjMap current) { var services = new ServiceCollection(); var reg = new StObjContextRoot.ServiceRegister(TestHelper.Monitor, services, startupServices); var configureArgs = new AutomaticServicesConfigurationEventArgs(current, reg); var hIng = _automaticServicesConfiguring; if (hIng != null) { using (_monitor.Monitor.OpenInfo("Raising Automatic services configuring event.")) { hIng(this, configureArgs); } } if (!reg.AddStObjMap(current)) { Throw.Exception("AddStObjMap failed. The logs contains detailed information."); } var hEd = _automaticServicesConfigured; if (hEd != null) { using (_monitor.Monitor.OpenInfo("Raising Automatic services configured event.")) { hEd(this, configureArgs); } } return(services.BuildServiceProvider()); }
StObjContextRoot.ServiceRegister IStObjEngineTestHelperCore.GetFailedAutomaticServicesConfiguration(StObjCollector c, Func <StObjEngineConfiguration, StObjEngineConfiguration>?engineConfigurator, SimpleServiceContainer?startupServices) { IStObjMap map = DoCompileAndLoadStObjMap(c, engineConfigurator, useEmbeddedStObjMapIfPossible: false).Map; var reg = new StObjContextRoot.ServiceRegister(TestHelper.Monitor, new ServiceCollection(), startupServices); reg.AddStObjMap(map).Should().BeFalse("Service configuration failed."); return(reg); }
/// <summary> /// Configures this <see cref="IServiceCollection"/> by registering the <see cref="IStObjMap.StObjs"/> and /// the <paramref name="map"/> itself as Singletons, by calling <see cref="StObjContextRoot.RegisterStartupServicesMethodName"/> /// and then <see cref="StObjContextRoot.ConfigureServicesMethodName"/> on all the <see cref="IStObjObjectMap.FinalImplementations"/> that expose /// such methods and by registering the <see cref="IStObjServiceMap.SimpleMappings"/> and <see cref="IStObjServiceMap.ManualMappings"/> mappings. /// Any attempt to register an already registered service will be ignored and a warning will be emitted. /// <para> /// If the registration fails for any reason (file not found, type conflicts, etc.), a <see cref="CKException"/> is thrown. /// </para> /// </summary> /// <param name="services">This service collection to configure.</param> /// <param name="monitor">The monitor to use. Must not be null.</param> /// <param name="map">StObj map to register. Can not be null.</param> /// <param name="startupServices"> /// Optional simple container that may provide startup services. This is not used to build IRealObject /// (they must be independent of any "dynamic" services), however registered services become available to /// any <see cref="StObjContextRoot.ConfigureServicesMethodName"/> methods by parameter injection. /// </param> /// <returns>This services collection.</returns> public static IServiceCollection AddStObjMap(this IServiceCollection services, IActivityMonitor monitor, IStObjMap map, SimpleServiceContainer?startupServices = null) { var reg = new StObjContextRoot.ServiceRegister(monitor, services, startupServices); if (!reg.AddStObjMap(map)) { throw new CKException("AddStObjMap failed. The logs contains detailed information."); } return(services); }
AutomaticServicesResult IStObjEngineTestHelperCore.CreateAutomaticServices(StObjCollector c, Func <StObjEngineConfiguration, StObjEngineConfiguration>?engineConfigurator, SimpleServiceContainer?startupServices, Action <StObjContextRoot.ServiceRegister>?configureServices) { var loadResult = DoCompileAndLoadStObjMap(c, engineConfigurator, true); var reg = new StObjContextRoot.ServiceRegister(TestHelper.Monitor, new ServiceCollection(), startupServices); reg.AddStObjMap(loadResult.Map).Should().BeTrue("Service configuration succeed."); configureServices?.Invoke(reg); return(new AutomaticServicesResult(loadResult, reg, reg.Services.BuildServiceProvider())); }