调整注入
This commit is contained in:
parent
3992bb3f9e
commit
3b292ba334
@ -29,6 +29,6 @@ namespace Infrastructure.Attribute
|
||||
|
||||
public enum LifeTime
|
||||
{
|
||||
Transient, Scoped, Singleton
|
||||
Transient, Scoped, Singleton, BackgroundService
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,6 +60,15 @@ namespace Infrastructure
|
||||
case LifeTime.Transient:
|
||||
services.AddTransient(serviceType, type);
|
||||
break;
|
||||
case LifeTime.BackgroundService:
|
||||
// 使用反射调用 AddHostedService
|
||||
var addHostedServiceMethod = typeof(ServiceCollectionHostedServiceExtensions)
|
||||
.GetMethods()
|
||||
.Where(m => m.Name == "AddHostedService" && m.IsGenericMethod)
|
||||
.First()
|
||||
.MakeGenericMethod(type);
|
||||
addHostedServiceMethod.Invoke(null, new object[] { services });
|
||||
break;
|
||||
default:
|
||||
services.AddTransient(serviceType, type);
|
||||
break;
|
||||
|
||||
@ -113,7 +113,6 @@ builder.Services.AddLocalization(options => options.ResourcesPath = "");
|
||||
//PLC进站后台服务注册
|
||||
//builder.Services.AddHostedService<PlcOutStationService_OP07_01>();
|
||||
//builder.Services.AddHostedService<PlcIntoStationService_OP70_01>();
|
||||
builder.Services.AddHostedService<PlcIntoStationService_OP080_1>();
|
||||
|
||||
//螺丝枪服务注册
|
||||
//builder.Services.AddHostedService<PF6ScrewGunService>();
|
||||
|
||||
@ -24,7 +24,7 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
||||
/// <summary>
|
||||
/// OP点散热胶GF1500
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(PlcIntoStationService_OP100), ServiceLifetime = LifeTime.Singleton)]
|
||||
[AppService(ServiceType = typeof(PlcIntoStationService_OP100), ServiceLifetime = LifeTime.BackgroundService)]
|
||||
public class PlcIntoStationService_OP100 : PlcIntoStationService_Common
|
||||
{
|
||||
public PlcIntoStationService_OP100(IOptions<OptionsSetting> options) : base(options)
|
||||
|
||||
@ -24,7 +24,7 @@ namespace RIZO.Service.PLCBackground.Stations.Into
|
||||
/// <summary>
|
||||
/// OP点散热胶GF1500
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(PlcIntoStationService_OP102), ServiceLifetime = LifeTime.Singleton)]
|
||||
[AppService(ServiceType = typeof(PlcIntoStationService_OP102), ServiceLifetime = LifeTime.BackgroundService)]
|
||||
public class PlcIntoStationService_OP102 : PlcIntoStationService_Common
|
||||
{
|
||||
public PlcIntoStationService_OP102(IOptions<OptionsSetting> options) : base(options)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user