Injection of IUrlHelper in ASP.NET Core

后端 未结 6 1945
借酒劲吻你
借酒劲吻你 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:57

    For Net Core 2.0

    Add this after service.AddMvc()

    services.AddSingleton();
    services.AddScoped(factory =>
    {
        var actionContext = factory.GetService()
                                       .ActionContext;
        return new UrlHelper(actionContext);
    });
    

提交回复
热议问题