-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templates
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
For asp .net core 9 and lower, you could inject the url helper like this:
services.AddScoped<IUrlHelper>(x =>
{
var actionContext = x.GetRequiredService<IActionContextAccessor>().ActionContext;
var factory = x.GetRequiredService<IUrlHelperFactory>();
return factory.GetUrlHelper(actionContext);
});
ActionContextAccessor is now obsolete, in the future that would probably mean there'd be no way to get an actioncontext (and also no way to get the url helper).
My suggestions would be:
- Make sure you can construct url helpers with the new
EndpointMetadataCollection - Make the url helper available as a scoped service by default in the dependency injection
Expected Behavior
For a service not to depend on obsoleted classes, for there to be a supported way of using IUrlHelper
Steps To Reproduce
The traditional way of instantiating IUrlHelper is now giving warnings, and in the future will be impossible:
services.AddScoped<IUrlHelper>(x =>
{
var actionContext = x.GetRequiredService<IActionContextAccessor>().ActionContext;
var factory = x.GetRequiredService<IUrlHelperFactory>();
return factory.GetUrlHelper(actionContext);
});
Exceptions (if any)
No response
.NET Version
10.0.10
Anything else?
No response
maxle5, WGroenestein, failwyn and jcageman
Metadata
Metadata
Assignees
Labels
area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templates