Ideally, controllers in a Spring MVC application must receive a request, despatch the request to an API, load the results (of the invocation) on to the model (for the view to subsequently render it) and forward to a view. They should do no more.
My controllers do far more than this today and I would like to move certain resposibilities away from the controller on to other APIs. My application design today (pretty typical):
controller <-> Service API <-> DAO <-> DB
The controller today fills up the delta between what the web app needs and what the Service API delivers. I would like to place extra layer/layers between the controller and service API that chew away at this delta. My question is what layer(s) should these be and what should the responsibilities of these new layer(s)?
My current Idea is as follows
controller <-> controller helper <-> Business API <-> Service API <-> DAO <-> DB
Controller helper (web context aware - will depend on Model, HttpServlet and other web context classes):
- Convert entities to DTO objects (2 way)
- Resolve IDs to entities. E.g. Controller looks up a student i.d. (using a key) and converts it to a Student entity.
Business API (no web context dependency - can be JUnit tested):
- Acts as a Facade. Invoking multiple service APIs to achieve one business request.
- Providing APIs that are specifically tailered for the web app.
Would you solve this a different way? Are there any resources (books, articles etc...) relating to this specific issue?
Some of previous discussions that did not answer my question:
Designing mvc controller layer
Service layer = Application layer = GRASP Controller layer
Moving Validation, Html Helpers to Service Layer in MVC
Thanks, Vijay