Injection of IUrlHelper in ASP.NET Core

后端 未结 6 1944
借酒劲吻你
借酒劲吻你 2020-12-05 17:29

In RC1, IUrlHelper could be injected in services (with services.AddMvc() in startup class)

This doesn\'t work anymore in <

6条回答
  •  暖寄归人
    2020-12-05 17:46

    For .Net Core 2.0

    services.AddMvc();
    
    services.AddScoped(x =>
    {
       var actionContext = x.GetRequiredService().ActionContext;
       var factory = x.GetRequiredService();
       return factory.GetUrlHelper(actionContext);
    });
    

提交回复
热议问题