Esempio n. 1
0
 /// <summary>
 /// Adds a startup task to be executed when the silo has started.
 /// </summary>
 /// <param name="builder">
 /// The builder.
 /// </param>
 /// <param name="startupTask">
 /// The startup task.
 /// </param>
 /// <param name="stage">
 /// The stage to execute the startup task, see values in <see cref="ServiceLifecycleStage"/>.
 /// </param>
 /// <returns>
 /// The provided <see cref="ISiloHostBuilder"/>.
 /// </returns>
 public static ISiloHostBuilder AddStartupTask(
     this ISiloHostBuilder builder,
     IStartupTask startupTask,
     int stage = ServiceLifecycleStage.Active)
 {
     return(builder.AddStartupTask((sp, ct) => startupTask.Execute(ct), stage));
 }
Esempio n. 2
0
        /// <summary>
        /// Starup process, by default it scans assemblies, sorts modules, configures container, and runs startup for each module
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public virtual IStartupContext ConfigureLocator(IStartupConfiguration config)
        {
            IStartupTask startupTaskWithStartModules = null;
            var          startupTaskContext          = new StartupTaskContext(_enableImport, _locatorRegistryFactory, config, _locatorDefaultRegistrations, _finalizeRegistry);

            foreach (var task in CreateStartupTasks())
            {
                task.Prepare(startupTaskContext);

                if (task is IStartupTaskWithStartupModules withStartupModules && withStartupModules.ExecuteStartupModules)
                {
                    startupTaskWithStartModules = withStartupModules;
                    continue;
                }

                task.Execute(config.TimedTaskManager);
            }

            if (startupTaskWithStartModules is null)
            {
                throw new Exception("No IStartupTaskWithStartupModules was used in startup tasks!");
            }

            // optionally allows delaying startup until later, must be implemented on IStartupConfiguration instances
            _delayedStart = () => startupTaskWithStartModules.Execute(config.TimedTaskManager);

            if (!_enableDelayedStartupModules)
            {
                TryExecuteStartupModules();
            }

            return(startupTaskContext.Get <IStartupContext>());
        }
Esempio n. 3
0
 public static void Run(IStartupTask task)
 {
     task.Execute();
 }