How To Use Dependency Injection In Unity3d with Zenject

Поделиться
HTML-код
  • Опубликовано: 7 ноя 2024

Комментарии • 31

  • @Joyz0r
    @Joyz0r 6 лет назад +1

    really helpful, gonna try this in my next project thanks

    • @dilmerv
      @dilmerv  6 лет назад +1

      Awesome I am glad you found it helpful :) have a great day !

  • @matuskokoska5108
    @matuskokoska5108 5 лет назад +1

    Thank you for a nice demonstration, now I will be injecting like a total junkie while keeping it totally legal

    • @dilmerv
      @dilmerv  5 лет назад

      Hehe sounds good and thanks for watching my friend !

  • @blitzkreig4887
    @blitzkreig4887 Год назад +1

    Is Zenject useful in 2022 production codebase ? Or is there a better alternative for IoC and Dependency Injection ? Thanks

    • @dilmerv
      @dilmerv  Год назад

      I personally haven’t seen many options and Zenject is what I have used with clients in the past, it really depends on the size of the project, if the project is small I normally use a singleton approach else Zenject.

  • @draganstamenkovic8072
    @draganstamenkovic8072 5 лет назад

    Keep it going Dilmer! :)))

    • @dilmerv
      @dilmerv  5 лет назад

      Thanks Dragan much appreciated !

  • @РоманЛебідь-ш3ы
    @РоманЛебідь-ш3ы Год назад

    Does it make sence to use interfaces for such classes like managers? I assume that they couldn't have other interpretations

    • @dilmerv
      @dilmerv  Год назад

      Makes complete sense to use interfaces, it helps with mocking and allows for better testing. In this case, I probably didn't but this is an older video. Thanks for your feedback!

  • @rafaelalcantara5741
    @rafaelalcantara5741 4 года назад

    Very nice video!
    I have a question: let's say I want to inject an AudioManager class, which implements an interface IAudioManager, how can I say to Zenject that the AudioManager implementation needs an AudioSource Unity component?

  • @artyomarshakyan1500
    @artyomarshakyan1500 2 года назад

    is this good to use in AR applications with different modules?
    Currently, I'm using a singleton design pattern, and have an idea to refactor the app.
    So should i use it?

    • @Bananenbauer123
      @Bananenbauer123 Год назад

      You got an answer to this? I have also thus far been using Singletons, but I fear this is going to lead to tight coupling and I don't like it. Feels completely wrong to do (because in my job we are currently being taught to use dependency injection and it is a staple in web app development).

  • @MalikenGD
    @MalikenGD 6 лет назад +2

    So you showed how to use Zenject, but why would I want to use Zenject? Can you give me a long explanation for the reason i'd use this in my projects if it's just another version of design patterns?

    • @dilmerv
      @dilmerv  6 лет назад +1

      Hi and thanks for your message. Dependency injection is just another design pattern, another tool, it is up to you to decide how you want to maintain your code, which honestly doesn’t prevent you from mixing patterns, you could have singletons, dependency injection, and many more patterns all in the same project, however it is important to understand the implications of each to help you build better and more maintainable code long term.

    • @MalikenGD
      @MalikenGD 6 лет назад +1

      @@dilmerv Okay well when would YOU use dependency injection primarily? What is the main use case for it?

    • @dilmerv
      @dilmerv  6 лет назад +1

      The main use is to have your instance lifecycle be managed in a container, you don’t have to worry about instantiation of dependencies, you can also take advantage of it by injecting mock instances for creating unit tests.

    • @The28studio
      @The28studio 5 лет назад +4

      Using DI is ùainly to decouple your code , your object shouldn't be the one creating or getting dependencies , now why ? 99% your code broke or produce bugs because of dependecies , almost all exepotions you got are about them , having them on one place is perfect for : finding bugs , exytending code , and testing .
      Go practice the SOLID principales and you will see why DI is a good idea.
      it sounds overkill for simple examples like this one but the more your code extend the more this pattern become handy .

    • @dilmerv
      @dilmerv  5 лет назад

      Thanks for the detail explanation !

  • @buzzmattn6539
    @buzzmattn6539 4 года назад

    Zenject is out of the Asset Store?

    • @dilmerv
      @dilmerv  4 года назад

      Correct and also in GitHub github.com/modesttree/Zenject

    • @mathijsbakker4646
      @mathijsbakker4646 4 года назад

      Hi! Great Content! @@dilmerv The continuation of Zenject is called Extenject. github.com/svermeulen/Extenject
      And in the UAS here: assetstore.unity.com/packages/tools/utilities/extenject-dependency-injection-ioc-157735

    • @MilanObrtlik
      @MilanObrtlik 4 года назад

      @@mathijsbakker4646 Very nice, thanks for posting.

  • @krazykewl7982
    @krazykewl7982 5 лет назад

    Tronlib....trongrid js lib

    • @dilmerv
      @dilmerv  5 лет назад +1

      I haven’t heard of it can you send me a link ?

    • @krazykewl7982
      @krazykewl7982 5 лет назад

      @@dilmerv its a Crypto library for tron and am stuck

  • @sergey7976
    @sergey7976 5 лет назад +1

    Sorry, not recommended Zenject

    • @dilmerv
      @dilmerv  5 лет назад

      I would be curious to know why ?

    • @sergey7976
      @sergey7976 5 лет назад

      If you have a small non enterprise project it's ok but not a pro solution. In Unity for small projects DI not necessary. And better using new Entity Component System.

    • @samriviera6299
      @samriviera6299 5 лет назад

      @@sergey7976 I disagree. Even for small projects DI is recommended. Why would you write bad code, just because the project is small? You don't have to use Zenject, but you should apply the concept of dependency injection.

    • @sergey7976
      @sergey7976 5 лет назад

      @@samriviera6299 Using DI not always means your code is perfect and vice versa.