1.首先给configure里面添加一个参数 IServiceProvider serviceProvider (默认没有,需手动添加),如下所示
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider)
2.调取服务如下
using (var scope = serviceProvider.CreateScope())
{
var ESSever = scope.ServiceProvider
.GetRequiredService<IESSever>();
var EFSever = scope.ServiceProvider
.GetRequiredService<IEFSever>();
new Affair.AffairWorks(EFSever, ESSever).HangFrieJobs();//定时或周期任务注册;
}