In what layer do controllers fit in layered architecture/DDD
T

1

7

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?

Thach answered 18/3, 2017 at 11:31 Comment(0)
S
9

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.

Sidewheel answered 18/3, 2017 at 14:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.