Is there any MVC framework around that applies POCO concept to controllers ?
Example:
Suppose I don't want to make my controller dependent on any web framework, in the way that I don't need to inherit from framework Controller class anymore.
Instead, I want to just specify routes with some rules, describing how to map requests to methods and parameters of my POCO controller class instance.
Maybe little example below can explain it better.
Imagine we can have routing like this:
routes.MapPOCOController<MyPOCO>("MyWebAppName/{method}/{*parameters}", () => _container.Resolve<MyPOCO>());
routes.IfMethodReturns<MyCustomRedirectResult>().PerformRedirect(result => result.Url);
and then your controller class is just a POCO object:
public class MyPOCO {
public User GetUser(Guid userId) {...}
public string Home() {
return _razorEngine.Render("~/Views/Home/Index.cshtml", new HomeModel { Message = "Hello world!"});
}
public object RenderSomePageOrRedirect()
{
if(blabla)
return new MyCustomRedirectResult("/profile");
else
return _razorEngine.Render( ... );
}
...
}
- In first method "GetUser" JSON serialization could happen automagically like in mvc4.
- In second method "Home" we need to render our views manually as a string, so this would give you more flexibility, like combining different engines or writing a custom one in much more natural way than it happens in current asp.mvc implementation.
- In third method "RenderSomePageOrRedirect" we are not tight to current RedirectResult implementation and can use whatever class that works, and then map it properly in routes.
Is there any framework around that already implemented at least one of the mentioned concepts ? ... maybe some "contrib" library?
The reasons why I'm looking for such functionality are:
- I want to follow DRY principle and don't want to mix request/response mapping code with the business logic in the controller (you can't do both with current mvc implementations that I'm aware of)
- I want to make my controller classes usable in multiple contexts, so, it's easier for unit-testing, for reusing and so on. (code becomes more DRY when you reusing same controllers in different web applications: you simply need to adjust routes a bit)
- It's just a gut feeling that this way of doing things is better, sorry, my words renderer gives up (
PS: my appreciation to people (StriplingWarrior especially) who commented below and helped me to form this question properly!