相关疑难解决方法(0)

如何在控制器外部访问RequestContext?

背景

我试图将业务逻辑从控制器转移到他们自己的服务中.

调节器

public class AccountController : Controller
{
    private readonly IAccountService _accountService; 

    public AccountController(IAccountService accountService)
    {
        _accountService = accountService;
    }

    ....
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Unity注入依赖项.我想Url.GenerateUrl()在实现中使用helper方法IAccountService但是Url是针对控制器的属性.

我查看了MVC源代码,看看它是如何完成的,但它要求我RequestContext从控制器外部访问,我不知道该怎么做.

如何从控制器外部访问RequestContext?如果这不能解决我的问题,我如何解决我的设置问题?

asp.net-mvc dependency-injection urlhelper requestcontext

19
推荐指数
2
解决办法
2万
查看次数