Converting a POCO Class as Controller in ASP.NET vNext | ASP.NET MVC Programmer Guide | ASP.NET MVC Tutorial

In vNext of ASP.NET MVC is the ability to use POCO classes as controllers. No need to inherit a controller class.
By default, as long as your class is public, non-abstract, has a Controller suffix and is defined in an assembly that references any of the MVC assemblies (Microsoft.AspNet.Mvc.Core, Microsoft.AspNet.Mvc etc), it will be discovered as a valid controller. An example is shown below.
But you cannot do much with just a POCO class – since you typically need access to things like current HTTP request, View Data or current Principal. However, this can be achieved as the POCO controllers support convention-based property injection. This is achieved throughDefaultControllerFactory, which looks for the following properties:
  • – ActionContext and injects an instance of ActionContext there
  • – ViewData, and injects an instance of ViewDataDictionary there
  • – Url, and injects an instance of IUrlHelper there
So we could modify our controller accordingly:
And you have all the contextual information you might need – for example, HttpRequest and Principal are both hanging off ActionContext.
In addition to that, the helpers, such as the aforementioned IUrlHelper or IActionResultHelper, can also be constructor injected, since ASP.NET vNext has dependency injection all the way through.