Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

丁松杰 / Pole

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • Pole
  • src
  • Pole.Core
  • Startup.cs
Find file
BlameHistoryPermalink
  • dingsongjie's avatar
    完成 基本测试 · 3ac920dd
    dingsongjie committed 5 years ago
    3ac920dd
Startup.cs 1.29 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
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<StartupTask> tasks = new List<StartupTask>();
        public static void Register(Func<IServiceProvider, Task> method, int sortIndex = 0)
        {
            tasks.Add(new StartupTask(sortIndex, method));
        }
        internal static Task StartPole(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<IServiceProvider, Task> func)
            {
                SortIndex = sortIndex;
                Func = func;
            }
            public int SortIndex { get; set; }
            public Func<IServiceProvider, Task> Func { get; set; }
        }
    }
    public class StartupConfig
    {
        public StartupConfig(IServiceCollection services)
        {
            Services = services;
        }
        public IServiceCollection Services { get; }
        public Action<PoleOptions> PoleOptionsConfig { get; set; }
    }
}