private RunComponentsResult RunComponents(IEnumerable <IHostableComponentFactory> factories, IEnumerable <Assembly> componentsAssemblies, IConfiguration configuration, CancellationToken cancellationToken) { var cfg = ComponentConfiguration.Create(configuration); this.SetSharedLibrariesConfiguration(configuration, componentsAssemblies); var componentLoader = new ComponentAssemblyLoader(this.loader); var components = factories .Select(f => f.CreateComponent(componentLoader, cfg)) .ToArray(); var task = Task.Factory.StartNew( () => { foreach (var component in components) { component.Start(); // TODO: should pass the cancellationToken } }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default); return(new RunComponentsResult { StartTask = task, Components = components }); }