4

Could anyone please explain the difference between onion architecture and Layered architecture using dependency inversion? They look exaclty the same to me. Any input is greatly appreciated :)

mike john
  • 63
  • 4
  • 2
    You might find this Mark Seemann's [article](http://blog.ploeh.dk/2013/12/03/layers-onions-ports-adapters-its-all-the-same/) interesting. – MaxSC Dec 10 '13 at 16:31

1 Answers1

3

I've always thought of it exactly that way: N-tier architecture meets DI--with a couple of constraints.

The most important thing is that code in inner layers is not coupled to code in outer layers (controlled direction of coupling). I also constrain myself layers can only communicate with the layer immediately beneath them (controlled depth of coupling). To my knowledge, no one else is advocating that particular constraint, and Palermo specifically rejects it.

Chris McKenzie
  • 3,203
  • 1
  • 24
  • 33
  • Thank you for taking the time to respond to my question. So essentially, When you opt for DI and using interfaces to decouple depedendencies, you are transforming your architecture to Onion architecture( from N Layered ). Let me know if this statement is incorrect. – mike john Dec 04 '13 at 22:33
  • Also, are application services( AKA service layer pattern ) considered part of the core? or is something that is usually placed in a different project/module from the core? – mike john Dec 04 '13 at 22:35
  • What I always say is that the question *which* layers you have and *what* their respective responsibilities they have is optional. Palermo is a DDD guy and I'm not so his implementation would be quite different from mine. As a general rule the interfaces and any contracts they expose are part of your onion layers. The implementations of those interfaces is considered to be infrastructure. – Chris McKenzie Dec 04 '13 at 22:53
  • For my money your first statement is correct as long as you are observing the direction (and in my case the depth) of your dependencies. Others may have a more contoured opinion, but I think you're essentially right. – Chris McKenzie Dec 04 '13 at 22:53