So, I've seen some questions about it here but none of them was specific about it neither answered my doubt.
In a layered architecture/DDD application, in what layer would a controller (the "C" in common MVC applications) fit? I've read in different places that it could be in the UI layer or in the application layer but I still couldn't wrap my head around what is the right layer.
I'm reading Eric Evans' DDD and until the point I've reached of the book I couldn't figure it out yet. I noticed he says that if the UI layer is not complex you can merge it with the application layer. Would this make the same for the controller?
MVC is usually a UI architecture and therefore the controller would be part of the UI, calling upon application services and then translating back responses into a suitable format for the UI.
If your application is complex enough to justify DDD then it most likely is complex enough to justify segregating the UI and the application layers.
Still, it's a good reflex to think and avoid over-engineering. If you judge that the segregation is not necessary right now then nothing prevents you from using your controllers as application services and refactor later if needed.
With the new era of single-page web applications where the MV* architecture lives on the client, the segregation comes naturally because the application layer lives on a different tier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With