Skip to content

Instantly share code, notes, and snippets.

@ZhenDeng
Created May 1, 2019 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZhenDeng/dcb50ddf1a1e904229771fa854b4e92d to your computer and use it in GitHub Desktop.
Save ZhenDeng/dcb50ddf1a1e904229771fa854b4e92d to your computer and use it in GitHub Desktop.
in startup.cs
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
services.AddScoped<IUrlHelper>(x => {
var actionContext = x.GetRequiredService<IActionContextAccessor>().ActionContext;
var factory = x.GetRequiredService<IUrlHelperFactory>();
return factory.GetUrlHelper(actionContext);
});
then could inject IUrlHelper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment