Dependency Injection in Go

Поділитися
Вставка
  • Опубліковано 4 лют 2025
  • Dependency Injection in Golang
    Neovim config: github.com/adi...
    Twitter: / adib_hanna

КОМЕНТАРІ • 24

  • @theedgardev
    @theedgardev 25 днів тому +1

    This is the best explanation I've seen so far! I understood DI, thanks!

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

    thank you very much for a such simple explanation, I couldn't believe I watched too many videos before and they all failed to explain what dependency injection is, coming from another programming language I was really frustrated, you saved my day :) keep the great work, and keep your videos simple 💫❤

  • @fixer8173
    @fixer8173 9 місяців тому +2

    In case you wonder if it is worth creating videos regularily, thanks for that a lot, your videos are super helpful and instructive, hope for many more ;)

    • @adibhanna
      @adibhanna  9 місяців тому +1

      Thank you! It’s been difficult to stay consistent, but im glad to be back at it

  • @joselima7655
    @joselima7655 2 місяці тому

    Wow very nice explanation. And great vim skills. I ended up here because of your zed videos. Are you still using zed? I’m working to transition but it’s taking a while. Thanks for the videos +sub . What colorscheme is this ?

    • @adibhanna
      @adibhanna  2 місяці тому

      thank you! I'm not using Zed, still using Neovim. they both use the same open-source LSPs, so the experience regarding code intelligence is pretty much the same. Neovim offers more options for customizability!

  • @martinndegwa7155
    @martinndegwa7155 5 місяців тому

    Best explanation. Thank you for this.

  • @TheMouseJerry-du1md
    @TheMouseJerry-du1md 9 місяців тому

    Brilliant Video. Pls share more golang videos and most used patterns in real time production code and also how one can use external packages that contains interfaces and struct types and what and when we can initialise or embed the in our code? U got me subscribed with this one video and hoping to see more...

    • @adibhanna
      @adibhanna  9 місяців тому

      thank you! planning to release a lot of Go videos

  • @Suraj-tz3oq
    @Suraj-tz3oq 7 місяців тому

    What if i have multiple dependencies like db, external service, ... other dependencies and they are dependent interdependent as well

  • @KuzyoYaroslav
    @KuzyoYaroslav 9 місяців тому

    Great video. Could you explain please why constructor function always returns pointer ?

    • @EverRusting
      @EverRusting 9 місяців тому

      I want to answer if I can, first of all, those are more like factory or generator functions, not constructors.
      Second, idk about Go but in C++ when you work with objects (or non primitive types), you usually want to pass the reference instead of the whole object.
      One reason for this is pass by value clones the entire object and also it's a different object every time because it's a clone.
      When you pass the pointer, it's the same object every time and in this case this is the desired outcome.

    • @gggalahad
      @gggalahad 9 місяців тому +1

      ​@@EverRusting Yeah but when I return pointer from function (method, constructor, whatever), doesn't it goes to heap? When I'm turning on gc in vscode or goland, it says that returned pointer goes to heap every time. And doesn't it means that garbage collector will do some work in the future, and doesn't it much bigger work than copy value from one stack frame to another?

    • @MyroslavSuprun
      @MyroslavSuprun 9 місяців тому

      @@gggalahad I have started reading Learning Go v2 recently and the author says the same thing. If you pass a pointer, it goes to the heap, and most times it's better to pass value instead of a pointer.
      Unless it's a struct with a lot of values.
      A quote from the book: "Most of the time, you should use a value. Values make it easier to understand how and when your data is modified. A secondary benefit is that using values reduces the amount of work that the garbage collector has to do."
      But I still see that most built-in go packages return pointer instead of a value. Like gzip.NewReader, errors.New etc.

  • @hma8244
    @hma8244 3 місяці тому

    Clean! Thanks man

  • @ayoubelmhamdi7920
    @ayoubelmhamdi7920 9 місяців тому

    you show us some codes, but the intuition is start from hello word to wrote all words, without autocompletions lile copilot....
    using copilot ia the the teacher that use paper to vopy past in broad.

  • @mahdertekola6932
    @mahdertekola6932 2 місяці тому

    Golden!

  • @Lohan_Guedes
    @Lohan_Guedes 9 місяців тому

    font name?

    • @Tarekconqueso
      @Tarekconqueso 9 місяців тому

      I believe that's jetbrains mono

    • @adibhanna
      @adibhanna  9 місяців тому

      berkeleygraphics.com/typefaces/berkeley-mono/

  • @Suraj-tz3oq
    @Suraj-tz3oq 7 місяців тому

    Ide?

  • @NullMcNull
    @NullMcNull 5 місяців тому

    This video is a nice explanation how to use interfaces instead of concrete instances, but it does not explain dependency injection at all. With dependency injection you build a provider (ioc container) that provides (injects) the concrete instances to methods.