A new feature coming in ASP.NET MVC 6 is the ability to use POCO (Plain Old CLR Object) classes as controllers. Meaning no need for a base class or interface implementation
A class will be discovered as a valid controller if the following is true.
- Controller class has a Controller suffix
-
Containing project references one of the following assemblies:
- Microsoft.AspNet.Mvc
- Microsoft.AspNet.Mvc.Core
- Microsoft.AspNet.Mvc.ModelBinding
- Microsoft.AspNet.Mvc.Razor
- Microsoft.AspNet.Mvc.Razor.Host
- Microsoft.AspNet.Mvc.TagHelpers
POCO controllers support property or constructor injection via the DefaultControllerFactory giving access to things like View DATA or the current HTTP request.
public class ExamplePOCOController
{
private readonly IUrlHelper _urlHelper;
public ExamplePOCOController(IUrlHelper urlHelper){
_urlHelper = urlHelper;
}
public string SayHello()
{
return new ContentResult() { Content = "Hello, I'm a POCO controller" };
}
}