Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move GetActionContextAsync and its related stuff to abstract place #16554

Closed
infofromca opened this issue Aug 13, 2024 · 1 comment · Fixed by #16557
Closed

move GetActionContextAsync and its related stuff to abstract place #16554

infofromca opened this issue Aug 13, 2024 · 1 comment · Fixed by #16557
Labels
enhancement SEO Search Engine Optimizations

Comments

@infofromca
Copy link
Contributor

Is your feature request related to a problem? Please describe.

under public class SeoMetaSettingsHandler and its related
private readonly IActionContextAccessor _actionContextAccessor;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IUrlHelperFactory _urlHelperFactory;

Describe the solution you'd like

move
private readonly IActionContextAccessor _actionContextAccessor;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IUrlHelperFactory _urlHelperFactory;
and
GetActionContextAsync
to a topService, because many modules will use the same logic.

@Piedone Piedone added the SEO Search Engine Optimizations label Aug 13, 2024
@Piedone
Copy link
Member

Piedone commented Aug 13, 2024

Moving injected dependency to a parent class is only marginally useful since you still have to write the constructor in a child class.

Factoring out this method can be useful:

internal static async Task<ActionContext> GetActionContextAsync(HttpContext httpContext)
{
var routeData = new RouteData();
routeData.Routers.Add(new RouteCollection());
var actionContext = new ActionContext(httpContext, routeData, new ActionDescriptor());
var filters = httpContext.RequestServices.GetServices<IAsyncViewActionFilter>();
foreach (var filter in filters)
{
await filter.OnActionExecutionAsync(actionContext);
}
return actionContext;
}

Because it's duplicated here and here. These examples also show that these should be centralized in some kind of static helper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement SEO Search Engine Optimizations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants