fix: 修复 _=Task.Run() 使用abp的ApplicationService提供的LazyServiceProvider创建scope出现嵌套scope创建失败的异常
解决方法:修改为IServiceScopeFactory创建scope的方式
This commit is contained in:
parent
8f1cd74163
commit
4f5f8b4cfa
@ -22,6 +22,13 @@ namespace SJZY.Track.Application.Services.TimerTaskss;
|
|||||||
[ApiExplorerSettings(GroupName = "定时任务")]
|
[ApiExplorerSettings(GroupName = "定时任务")]
|
||||||
public class TrackPullTask : ApplicationService, ISingletonDependency
|
public class TrackPullTask : ApplicationService, ISingletonDependency
|
||||||
{
|
{
|
||||||
|
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||||
|
|
||||||
|
public TrackPullTask(IServiceScopeFactory serviceScopeFactory)
|
||||||
|
{
|
||||||
|
_serviceScopeFactory = serviceScopeFactory;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 定时任务刷新轨迹
|
/// 定时任务刷新轨迹
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -30,7 +37,7 @@ public class TrackPullTask : ApplicationService, ISingletonDependency
|
|||||||
[HttpPost("/TimerTask/Refresh")]
|
[HttpPost("/TimerTask/Refresh")]
|
||||||
public async Task<bool> RefreshForTaskAsync()
|
public async Task<bool> RefreshForTaskAsync()
|
||||||
{
|
{
|
||||||
using var serviceScope = LazyServiceProvider.CreateScope();
|
using var serviceScope = _serviceScopeFactory.CreateScope();
|
||||||
|
|
||||||
var provideQueries = serviceScope.ServiceProvider.GetRequiredService<IProvideQueries>();
|
var provideQueries = serviceScope.ServiceProvider.GetRequiredService<IProvideQueries>();
|
||||||
var configs = await provideQueries.GetAllPullConfigsAsync();
|
var configs = await provideQueries.GetAllPullConfigsAsync();
|
||||||
|
|||||||
@ -13,6 +13,13 @@ namespace SJZY.Track.Application.Services.TimerTaskss;
|
|||||||
[ApiExplorerSettings(GroupName = "定时任务")]
|
[ApiExplorerSettings(GroupName = "定时任务")]
|
||||||
public class TrackPushTask : ApplicationService
|
public class TrackPushTask : ApplicationService
|
||||||
{
|
{
|
||||||
|
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||||
|
|
||||||
|
public TrackPushTask(IServiceScopeFactory serviceScopeFactory)
|
||||||
|
{
|
||||||
|
_serviceScopeFactory = serviceScopeFactory;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 定时任务推送预警(》12小时没有推送的)
|
/// 定时任务推送预警(》12小时没有推送的)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -21,7 +28,7 @@ public class TrackPushTask : ApplicationService
|
|||||||
[HttpPost("/TimerTask/PushWarn")]
|
[HttpPost("/TimerTask/PushWarn")]
|
||||||
public async Task<string> PushWarnForTaskAsync()
|
public async Task<string> PushWarnForTaskAsync()
|
||||||
{
|
{
|
||||||
using var serviceScope = LazyServiceProvider.CreateScope();
|
using var serviceScope = _serviceScopeFactory.CreateScope();
|
||||||
|
|
||||||
var configs = serviceScope.ServiceProvider.GetRequiredService<IOptionsSnapshot<Track2InterfaceRelayOptions>>()
|
var configs = serviceScope.ServiceProvider.GetRequiredService<IOptionsSnapshot<Track2InterfaceRelayOptions>>()
|
||||||
.Value;
|
.Value;
|
||||||
|
|||||||
@ -16,11 +16,14 @@ public class TrackWarningTask : ApplicationService
|
|||||||
{
|
{
|
||||||
private readonly IOptionsSnapshot<Track2InterfaceRelayOptions> _options;
|
private readonly IOptionsSnapshot<Track2InterfaceRelayOptions> _options;
|
||||||
private readonly IOrderRepository _orderRepository;
|
private readonly IOrderRepository _orderRepository;
|
||||||
|
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||||
|
|
||||||
public TrackWarningTask(IOrderRepository orderRepository, IOptionsSnapshot<Track2InterfaceRelayOptions> options)
|
public TrackWarningTask(IOrderRepository orderRepository, IOptionsSnapshot<Track2InterfaceRelayOptions> options,
|
||||||
|
IServiceScopeFactory serviceScopeFactory)
|
||||||
{
|
{
|
||||||
_orderRepository = orderRepository;
|
_orderRepository = orderRepository;
|
||||||
_options = options;
|
_options = options;
|
||||||
|
_serviceScopeFactory = serviceScopeFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -63,7 +66,7 @@ public class TrackWarningTask : ApplicationService
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var serviceScope = LazyServiceProvider.CreateScope();
|
using var serviceScope = _serviceScopeFactory.CreateScope();
|
||||||
|
|
||||||
var forewarningNotifyService =
|
var forewarningNotifyService =
|
||||||
serviceScope.ServiceProvider.GetRequiredService<IForewarningNotifyService>();
|
serviceScope.ServiceProvider.GetRequiredService<IForewarningNotifyService>();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user