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.
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!
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?
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?
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).
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?
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.
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.
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 .
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
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.
@@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.
really helpful, gonna try this in my next project thanks
Awesome I am glad you found it helpful :) have a great day !
Thank you for a nice demonstration, now I will be injecting like a total junkie while keeping it totally legal
Hehe sounds good and thanks for watching my friend !
Is Zenject useful in 2022 production codebase ? Or is there a better alternative for IoC and Dependency Injection ? Thanks
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.
Keep it going Dilmer! :)))
Thanks Dragan much appreciated !
Does it make sence to use interfaces for such classes like managers? I assume that they couldn't have other interpretations
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!
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?
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?
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).
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?
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.
@@dilmerv Okay well when would YOU use dependency injection primarily? What is the main use case for it?
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.
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 .
Thanks for the detail explanation !
Zenject is out of the Asset Store?
Correct and also in GitHub github.com/modesttree/Zenject
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
@@mathijsbakker4646 Very nice, thanks for posting.
Tronlib....trongrid js lib
I haven’t heard of it can you send me a link ?
@@dilmerv its a Crypto library for tron and am stuck
Sorry, not recommended Zenject
I would be curious to know why ?
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.
@@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.
@@samriviera6299 Using DI not always means your code is perfect and vice versa.