Search code examples
design-patternsmodel-view-controllerarchitecturesoftware-designonion-architecture

How can MVC coexist with the Onion architecture?


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.


Solution

  • 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.