①安装包:
Microsoft.Extensions.DependencyInjection
②应用
主方法里面:
//接口 IService ,实现:Service ,方法:Execute();
var serviceProvider = new ServiceCollection()
.AddSingleton<IService,Service>()
.BuildServiceProvider();
var _service = serviceProvider.GetRequireService<IService>();
_service.Execute();
标签:Execute,依赖,service,serviceProvider,AspNetCore,var,控制台 From: https://www.cnblogs.com/jf-ace/p/17679192.html