Hexagonal Architecture (All You Need to Know)

Поділитися
Вставка
  • Опубліковано 22 гру 2024

КОМЕНТАРІ • 25

  • @simonegiuliani4913
    @simonegiuliani4913 10 місяців тому +4

    Thanks for the video! The dependency issue coming from a n-layered architecture can be simply resolved by putting all interfaces on a separate project and enforce the use of interfaces. I have worked with both clean and hex architectures in both java and c# and my personal experience is that they are a nightmare to work with as they are not intuitive at all and it's very difficult to onboard people. Use them carefully and try them for some time before productionising!

    • @gui.ferreira
      @gui.ferreira  10 місяців тому +5

      I believe that the nightmare starts when we don't keep it simple. That's why I like Hexagonal. It's easy to explain and to keep it in a simple way.

  • @AboutCleanCode
    @AboutCleanCode 10 місяців тому +4

    Great summary of the concepts of this architecture 👍How do you decide which third-party library you let into your hexagon? Or do you put "everything" behind a port? What about FluentValidations for example or the famous MediatR?

    • @gui.ferreira
      @gui.ferreira  10 місяців тому +1

      Excellent question. If the library serves the connection of my hexagon to the external world, it goes into an Adapter.
      Example: npgsql will be in an adapter, while MediatR will be part of my hexagon.
      Do you follow another approach?

    • @AboutCleanCode
      @AboutCleanCode 10 місяців тому

      @@gui.ferreira I try to be very strict and let as few libraries into my application logic directly as possible 😉

  • @erickgeneric
    @erickgeneric 2 місяці тому +2

    Well explained. Thank you!

  • @rmcgraw7943
    @rmcgraw7943 4 місяці тому +3

    I’ve used this long before it was ever given a name, and while most know it as Hex Arch, I call it XPlicit Arch, since architect is supposed to be about interfaces and contracts, not implementations. For you C guys out there, when he speaks of Ports, think Interface or abstract class, and adapters can be 2 things (either an interface implementing class or abstract class that implements that interface but serves as a translator). There is some cost to this architecture, as it’s not easy for junior or mid level coders to fathom at first, but it pays off for enterprise solutions. It’s Dependency Injection intensive, so it makes people code to interfaces, another plus. Also, it doesn’t have to be followed exactly, and you can use it as your enterprise core architecture, which it is ideal for, but it can also be applied in an complex application as well. For instance, a web portal might have it’s own entire hexagon that interacts with the “Core” enterprise hexagon. The main thing to realize is that nothing deals with concrete instances except the deepest regions in the Core of each hexagon. Everything is talking to each other via interfaces, allowing for future change and flexibility. Search “The Software Architecture Chronicles” by Herbert Graca for a thorough explanation on this architecture.

    • @gui.ferreira
      @gui.ferreira  4 місяці тому

      Thanks for sharing. I agree with you that it can be harder for a Junior, but I think it's easier to get it than other styles.
      Those articles by Herberto are amazing.

  • @santanu_barua
    @santanu_barua Місяць тому

    Excellant explanation with animation. Could you please tell me what animation tool did you use? thanks

  • @GiswaldCA
    @GiswaldCA 10 місяців тому +2

    Hi thanks for your videos. Can you maybe make one for Kafka Streams with dotnet?

    • @gui.ferreira
      @gui.ferreira  10 місяців тому

      Hi! Thanks 🙏
      I'm not sure If I'm the best person to talk about Streams. But I will add it to my list and think about it.
      Thanks for the suggestion.

  • @BarbarosYurttagul
    @BarbarosYurttagul 10 місяців тому +1

    This is a wonderful channel. I watched all your videos about hexagonal architecture. But I still have questions in my mind. I really can't see a difference between n-tier architecture and hexagonal when you applied dependency injection for every technology you used. For example, in data access layer, I can have an interface called IProductRepository which includes necessary methods. Then I can have a concrete class which name is like EFProductRepository implementing IProductRepository. If one day I would like to switch my ORM technology, then I can create another concrete class like DapperProductRepository implementing IProductRepository again. And it is still testable independent from technology. By using dependency injection, they are loose-coupled as well.

    • @gui.ferreira
      @gui.ferreira  10 місяців тому +1

      What if I told you that what you described is not n-tier architecture anymore? 😉 It's how we naturally fight the problems of multitier architecture.
      I know that Wikipedia is not perfect, but if we look into the multitier architecture it says:
      "A layer is on top of another, because it depends on it. Every layer can exist without the layers above it, and requires the layers below it to function."
      en.wikipedia.org/wiki/Multitier_architecture
      According to your description, your "business" layer no longer depends on the data access layer.
      Am I correct?

    • @BarbarosYurttagul
      @BarbarosYurttagul 10 місяців тому

      @@gui.ferreira You are right. My "business" layer doesn't depend on Data Access Layer. So, what is the name of this architecture then if it is not multi-tier or hexagonal?

    • @gui.ferreira
      @gui.ferreira  10 місяців тому +1

      ​@@BarbarosYurttagul From your description, you have a domain-centric architecture. On that family of architectures, you can find Hexagonal, Clean Arch or Onion.
      I would need to look into the complete blueprint to name it. However, the name is not the most important thing.
      If you apply the principles of Hexagonal, I bet you are in a good place.

  • @eulier1
    @eulier1 14 днів тому

    Do you provide or point to a place to put this architecture at practice for example in React/Next.js apps?.

    • @gui.ferreira
      @gui.ferreira  13 днів тому

      I've seen these two. They are not perfect, in my opinion, but they will give you an idea of what it should look like.
      github.com/Maua-Dev/hexagonal_arch_react_template
      github.com/juanm4/hexagonal-architecture-frontend

  • @duramirez
    @duramirez 7 місяців тому +3

    Hey don't bash on people who build their own ORM 😆 I still use the one I created back in 2007 (but ofc modernized it and keep it updated) and it works way way better than any ORM offered today in a fancy package. 😆

    • @gui.ferreira
      @gui.ferreira  7 місяців тому +1

      More than 15 years of utilization, already justifies the investment 😅

    • @duramirez
      @duramirez 7 місяців тому +1

      @@gui.ferreira tru tru 😀

  • @Cool-Game-Dev
    @Cool-Game-Dev 10 місяців тому +1

    I use a micro services architecture for my game dev, and this doesn’t really work for game dev, but I’ll keep it in the back of my mind!

    • @gui.ferreira
      @gui.ferreira  10 місяців тому

      I agree. In most microservices (when they are in fact micro) it usually isn't needed.

  • @GuilleMorton
    @GuilleMorton 8 місяців тому +1

    Is this aplicable to microservices? Is it needed then? Seems like over engineering for me. But also dont like thinking that this will be useful when working with monoliths only.

    • @gui.ferreira
      @gui.ferreira  7 місяців тому +1

      It's a tradeoff.
      You will get testability and device independence. But, if it's a tiny service, such as a Service with a single responsibility to ingest a queue into a database, you might not get much out of it.
      Even then, designing applications as a 3-part system (input, core, output) is not such a big overhead and can be useful. By the way, each part doesn't need to be a different project or package.