I wonder what is your approach on following subject:
let's say we have MVC structure with entities, repositories, controllers and service layer.
My approach to use above was pretty clear for me:
- controller uses services
- services perform manipulations to data when needed,
- services use repository classess to save and update data from db
- controller gets services output (when needed) and pushes it to view
However, yesterday I stumbled upon solution popular in Symfony2
world, in which
- controller has access to entityManager/sessionFactory
- controller uses services to perform manipulations to data
- controller uses entityManager/sessionFactory and repositories directly to perform database reads, saves and handle transactions.
At first I disagreed with second approach, I know it breaks some clean architecture principles, but... it is shown in a lot of official tutorials on Symfony2
website. So I thought it would be better to ask.
In other words: is it ok to make controller directly responsible for saving and retrieving data as well as handling transactions? What are ups and downs?