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; }
}
}