我需要一个UrlHelper在我的webapi vNext控制器中,所以我尝试使用构造函数注入它:
public BaseApiController(UrlHelper urlHelper)在我的Startup.cs中,我添加了:
services.AddTransient<UrlHelper, UrlHelper>();但是当我运行它时,它会出错,因为它不能解析ActionContext参数来实例化UrlHelper。所以我补充道:
services.AddTransient<ActionContext, ActionContext>();但是我得到了一个错误:
A circular dependency was detected for the service of type
'Microsoft.AspNet.Mvc.ActionContext'有什么建议吗?
发布于 2016-01-08 12:12:38
事实证明,我可以使用Url.Link来满足我的需要,所以我根本不需要UrlHelper。不完全是一个解决问题的方法,但它对我有效。
https://stackoverflow.com/questions/34672261
复制相似问题