2

The ASP.NET vNext Overview says you can create POCO controllers by injecting IActionResultHelper:

public class HomeController
{
    // Helpers can be dependency injected into the controller
    public HomeController(IActionResultHelper resultHelper)
    {
        Result = resultHelper;
    }

    private IActionResultHelper Result { get; set; }

    public ActionResult Index()
    {
        return Result.Json(new { message = "Poco controllers!" });
    }
}

I'm trying to implement this, however, I cannot find this interface. It appears that is no longer in the source code.

What is the current correct approach for creating POCO controllers?

4

2 に答える 2

1

2014 年 10 月 6 日の Visual Studio 14 の CTP リリースの時点で、サービスを挿入する方法は次のとおりです。

public class HomeController
{
    // Use the ActivateAttribute to inject services into your controller
    [Activate]
    public ViewDataDictionary ViewData { get; set; }

    public ActionResult Index()
    {
        return new ViewResult() { ViewData = ViewData };
    }
}

出典: ASP.NET MVC 6 入門 - Mike Wasson、asp.net

于 2014-10-29T10:57:24.007 に答える