using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Pole.Core { public static class Startup { static List tasks = new List(); public static void Register(Func method, int sortIndex = 0) { tasks.Add(new StartupTask(sortIndex, method)); } internal static Task StartRay(IServiceProvider serviceProvider) { tasks = tasks.OrderBy(func => func.SortIndex).ToList(); return Task.WhenAll(tasks.Select(value => value.Func(serviceProvider))); } private class StartupTask { public StartupTask(int sortIndex, Func func) { SortIndex = sortIndex; Func = func; } public int SortIndex { get; set; } public Func Func { get; set; } } } public class StartupConfig { public StartupConfig(IServiceCollection services) { Services = services; } public IServiceCollection Services { get; } public Action PoleOptionsConfig { get; set; } } }