Reputation: 197
I've seen people suggesting the implementation of MVC together with the Onion Archutecture. But how can the two coexist? Aren't they two distinct architectures? For example, where is the Controller in the Onion design?
I understand the combination of more than one design pattern, because they serve different purposes (behaviour, creation, etc), and can be independently implemented in different modules of the system, but I don't get how to implement two different architectures.
Upvotes: 4
Views: 2201
Reputation: 58444
The "onion architecture" mostly applies to the model layer and the various types of structures it contains (services, repositories, domain objects, mappers, units of work and etc.).
You also end up with various custom structures, like things you end up calling "adapters" and "generators" or various other names for things that pertain to business logic, but do not fit in any specific standard. But they are all end up in (hopefully) distinct layers.
But that's kinda the extent of it. The controllers are (supposed to be) very simple structures. And views are only marginally more complicated ... and that's assuming that you actually use presentation objects.
TL;DR: there is nothing preventing MVC from coexisting with onion architecture, but the MVC will end up as primary at the largest scale.
Upvotes: 5
Reputation: 2369
MVC would live on the outside of the onion and be responsible for view / API concerns, delegating any domain logic to the domain in the middle of the onion.
So imagine someone visits your homepage - this would be handled by a controller that would return a view - the model would be any information required by the view. If you needed some domain logic (let's say some special offers are shown on the homepage), the controller would delegate this to the domain - the logic wouldn't be inside the controller itself. Similarly, the domain would return some sort of domain object which would then typically need mapping into the model to be used by the view. This view is then returned in the response.
If you haven't done already, read up on hexagonal architecture as it's basically the same idea.
Upvotes: 4