Skip to content

Commit 96e17df

Browse files
committed
Remove obsolete IActionContextAccessor in WorkflowTypeStep
1 parent 1a687f6 commit 96e17df

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/OrchardCore.Modules/OrchardCore.Workflows/Recipes/WorkflowTypeStep.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using System.Text.Json;
22
using System.Text.Json.Nodes;
3+
using Microsoft.AspNetCore.Http;
34
using Microsoft.AspNetCore.Mvc;
4-
using Microsoft.AspNetCore.Mvc.Infrastructure;
55
using Microsoft.AspNetCore.Mvc.Routing;
66
using Microsoft.Extensions.Options;
7+
using OrchardCore.DisplayManagement.Extensions;
78
using OrchardCore.Json;
89
using OrchardCore.Recipes.Models;
910
using OrchardCore.Recipes.Services;
@@ -19,28 +20,28 @@ public sealed class WorkflowTypeStep : NamedRecipeStepHandler
1920
{
2021
private readonly IWorkflowTypeStore _workflowTypeStore;
2122
private readonly ISecurityTokenService _securityTokenService;
22-
private readonly IActionContextAccessor _actionContextAccessor;
23+
private readonly IHttpContextAccessor _httpContextAccessor;
2324
private readonly IUrlHelperFactory _urlHelperFactory;
2425
private readonly JsonSerializerOptions _jsonSerializerOptions;
2526

2627
public WorkflowTypeStep(IWorkflowTypeStore workflowTypeStore,
2728
ISecurityTokenService securityTokenService,
28-
IActionContextAccessor actionContextAccessor,
29+
IHttpContextAccessor httpContextAccessor,
2930
IUrlHelperFactory urlHelperFactory,
3031
IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions)
3132
: base("WorkflowType")
3233
{
3334
_workflowTypeStore = workflowTypeStore;
3435
_securityTokenService = securityTokenService;
35-
_actionContextAccessor = actionContextAccessor;
36+
_httpContextAccessor = httpContextAccessor;
3637
_urlHelperFactory = urlHelperFactory;
3738
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
3839
}
3940

4041
protected override async Task HandleAsync(RecipeExecutionContext context)
4142
{
4243
var model = context.Step.ToObject<WorkflowStepModel>();
43-
var urlHelper = GetUrlHelper();
44+
var urlHelper = await GetUrlHelperAsync();
4445

4546
foreach (var token in model.Data.Cast<JsonObject>())
4647
{
@@ -76,12 +77,14 @@ protected override async Task HandleAsync(RecipeExecutionContext context)
7677

7778
private IUrlHelper _urlHelper;
7879

79-
private IUrlHelper GetUrlHelper()
80+
private async Task<IUrlHelper> GetUrlHelperAsync()
8081
{
81-
// When 'UrlHelper' is instantiated outside a controller's action (e.g., in a BackgroundTask), the ActionContext is null.
82-
if (_urlHelper is null && _actionContextAccessor.ActionContext is not null)
82+
// In .NET 10, IActionContextAccessor is obsolete, so we create ActionContext directly
83+
if (_urlHelper is null && _httpContextAccessor.HttpContext is not null)
8384
{
84-
_urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext);
85+
var httpContext = _httpContextAccessor.HttpContext;
86+
var actionContext = await httpContext.GetActionContextAsync();
87+
_urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
8588
}
8689

8790
return _urlHelper;

0 commit comments

Comments
 (0)