Golang Dependency Injection Made EASY - The Repository Pattern

preview_player
Показать описание
In this Golang tutorial, I dive into the world of dependency injection in Golang using the Repository Pattern! I discuss the benefits of the pattern and explain some practical real-world examples.

By the end of this video, you'll have a solid understanding of how to use dependency injection/the repository pattern in your Golang projects to write more decoupled, maintainable, and testable code.

Commonly the repository pattern is seen within the ports and adapters pattern, or the "hexagonal architecture pattern". All these patterns work great with the repository pattern, and in fact I'd say its the easiest way to decouple your business logic.

Do you have any suggestions on dependency injection in Go? Hit me with it in the comments!

Рекомендации по теме
Комментарии
Автор

Ah, I have used this pattern without knowing this is what Dependency Injection is. Thanks for this video.

pratikkulkarni
Автор

Btw I'm using this pattern for over years in a lot of my Go projects. I ended up using IoC library like Wire or Fx to wire my dependency automatically due to my codebase get bigger overtime. What's your opinion of using IoC library like Wire or Fx? I personally disagree with that but somehow makes my work easier. Thanks!

TaqiA
Автор

This is so good! Its hard to find good content on Go about more advanced topics. Thats an easy subscribe from me!

skl
Автор

How do you handle the mapping between domain objects and db tables?

NiccoloFant
Автор

What does this look like when you start to have 10, 20, 30 repos and services? How can you organize them with this pattern in mind? Are all of the services and repos created in main, and passed down through closures?

christophercaldwell
Автор

this is good, but as projects gets bigger you will find harder to maintain. IoC library should be considered

Stupendousboy
Автор

I do it this way in most of my non-trivial Go work. The only aesthetically questionable part is the "newing up of all the things and injecting"- compared to Java Spring Boot, say (lol, but then you have to write Java). Otherwise, it's a total win, and you'll really thank yourself when it comes to unit testing.

inaccessiblecardinal
Автор

Nice content Brooo keep share your knowledge

ramdoni
Автор

Great video and thank you for describing where in real time one can see such usage. You got me subscribed and thumbs-up!

TheMouseJerry-dumd
Автор

This approach falls short. Interfaces should be defined where they are needed to follow the dependency inversion and the interface segregation rule.

ibrahimkoz
Автор

You just explained the general concept of DI, there was nothing specific to Go.
The hard hard is, how do you register dependencies and create a system that automatically injects the correct dependency. Sorry but you missed the point.

xff_
Автор

Isn't dependency injection an anti pattern?

Rundik