Honestly, this video took the core of dependency injection using tsyringe and decoupled it in approximately 7 minutes. Nice one Kris Foster, it's hard to find conciseness merged with in-depth these days.
I have this personal project made with NodeJS + Typescript. It is now getting bigger and is now having problems managing dependencies. I haven't thought of this problem before because I am originally an Angular dev and haven't had any problems with DI as it is automatically managed by Angular. I did a little research and found TypeDI and Inversify as the best recommendations from the community. I then read a comment in Reddit stating that there's a relatively new one which is Tsyringe and he said its his favorite(also maintained by Microsoft) so I watched it here in TH-cam. After watching this vid, I was like "Danm is looks like Angular, its so easy". I think I don't need to look on those 2 other options(TypeDI and Inversify) as this one is already enough for my requirements and I am comfortable with the syntax it is using. Nice explanation also, thanks.
I think the only thing that’s missing here is where you would be using interfaces rather than concrete implementations, which is where you’d likely start using a ServiceLocator; having said that I’m quite unfamiliar with this library and would be interested to see how they’ve went about usage in more complex applications
This is really good ...I noticed that you use class based implementations in express....could you do a video on how you structure an express app in class based implementations and testing it ... obviously with typescript...cheers 🔥
Great video, and thank you for choosing a package maintained by Microsoft! How about just having an index file for the controller where, with a function, you just manually export an instance of the controller with all its dependencies? That is, just creating your own container.
you say we are automatically injecting the dependencies, but not what that really means; like in the constructor, its specifying a type, is that just automatically picking that type as the dependency to inject too?
@Kris - Thank you for creating such a great content. I;m facing issue when Im testing my dependency services with Jest unit test framework. Would you mind to share if there is any sample code or tutorial?
don't get it you have a direct dependency in BookService for example, it's not like your're saying the injected dependency has to conform to an interface, its a class. How do I swap some other service in . What am I missing , this is obviously useful ?
I found an example in your github, but you weren't using tsyringe for dependency tree in your tests, Did u have any reason to do that? Thanks in advance for your attention
This was well done, and what it covers is good, but I feel like you missed explaining one of the main usages of DI and these containers, which is using mocks and setting those in the DI framework. It also doesn't explain how to handle the situation where a dependency that we want to autoInject requires parameters in the constructor. Both are pretty common imo.
? He set a service as autoinjected that had the repository as a dependency. Seems like he did show a situation where you need a depenency autoinjected that has a dependency itself in its constructor.
Everyone seems to tsyringe without any fear of the experimental state of the decorators. Can anyone elobare on this. Is this a non-issue or something i should be concerned about when building an application that needs to be maintained
Very helpfull video. However, your mixing up @injectable and @autoInjectable. Injectable should be used with "const instance = container.resolve(MyClass)" AutoInjectable should be used with "const instance = new MyClass()" and optional parameters
This is great information but I think your audio needs some tweaks. Everytime you take a breath and swallow I hear your spit. I feel like I'm watching ASMR XD
Honestly, this video took the core of dependency injection using tsyringe and decoupled it in approximately 7 minutes.
Nice one Kris Foster, it's hard to find conciseness merged with in-depth these days.
Great video! Was looking forever for this. Everyone else's videos are way too long and bloated. This is straight to the point.
Thank you for the nice feedback!
I have this personal project made with NodeJS + Typescript. It is now getting bigger and is now having problems managing dependencies. I haven't thought of this problem before because I am originally an Angular dev and haven't had any problems with DI as it is automatically managed by Angular. I did a little research and found TypeDI and Inversify as the best recommendations from the community. I then read a comment in Reddit stating that there's a relatively new one which is Tsyringe and he said its his favorite(also maintained by Microsoft) so I watched it here in TH-cam.
After watching this vid, I was like "Danm is looks like Angular, its so easy". I think I don't need to look on those 2 other options(TypeDI and Inversify) as this one is already enough for my requirements and I am comfortable with the syntax it is using. Nice explanation also, thanks.
Thank you for the feedback and good luck with your project!
Fantastic short course, exactly what I was looking for! Thank you so much!
Glad you enjoyed and thank you for the kind words!
I think the only thing that’s missing here is where you would be using interfaces rather than concrete implementations, which is where you’d likely start using a ServiceLocator; having said that I’m quite unfamiliar with this library and would be interested to see how they’ve went about usage in more complex applications
This was very helpful, short and straight to the point.
Excellent simple debunk of DI even for a beginner like me, awesome!
довольно интересно. Осталось научиться применять эти знания на практике)
This is really good ...I noticed that you use class based implementations in express....could you do a video on how you structure an express app in class based implementations and testing it ... obviously with typescript...cheers 🔥
Thanks for the feedback & suggestion @pranjal walia, I actually plan to make a couple of TypeScript videos next & that is one of them!
It worked beautifully, thanks
Man, you are a god. That's the first time that i understand di
thanks alot, this was exactly what i needed
Is tsyringe web compatible? I can imagine great usecase for React
Great video. Can you do another one in TSyringe for mocks + Jest + SuperTest?
Can u explain how to use this DI in React Component?
Great video, and thank you for choosing a package maintained by Microsoft! How about just having an index file for the controller where, with a function, you just manually export an instance of the controller with all its dependencies? That is, just creating your own container.
you say we are automatically injecting the dependencies, but not what that really means; like in the constructor, its specifying a type, is that just automatically picking that type as the dependency to inject too?
nice video, clean example!
@Kris - Thank you for creating such a great content. I;m facing issue when Im testing my dependency services with Jest unit test framework. Would you mind to share if there is any sample code or tutorial?
don't get it you have a direct dependency in BookService for example, it's not like your're saying the injected dependency has to conform to an interface, its a class. How do I swap some other service in . What am I missing , this is obviously useful ?
What if BookRepository have a dynamic property? E.g. library: 'library1'|'library2'. Can I control it from BookController?
do you mean these dependencies being injected in the BookRepository constructor?
great video bro, Did u have some example unit testing an application with tsyringe?
I found an example in your github, but you weren't using tsyringe for dependency tree in your tests, Did u have any reason to do that? Thanks in advance for your attention
This was well done, and what it covers is good, but I feel like you missed explaining one of the main usages of DI and these containers, which is using mocks and setting those in the DI framework. It also doesn't explain how to handle the situation where a dependency that we want to autoInject requires parameters in the constructor. Both are pretty common imo.
? He set a service as autoinjected that had the repository as a dependency. Seems like he did show a situation where you need a depenency autoinjected that has a dependency itself in its constructor.
Everyone seems to tsyringe without any fear of the experimental state of the decorators. Can anyone elobare on this. Is this a non-issue or something i should be concerned about when building an application that needs to be maintained
Nice!
Glad you enjoyed @Harel Tussi
Very helpfull video. However, your mixing up @injectable and @autoInjectable.
Injectable should be used with "const instance = container.resolve(MyClass)"
AutoInjectable should be used with "const instance = new MyClass()" and optional parameters
kool
Please place a pop filter in front of your mic, a lot of Ps and Ts are causing the audio to clip.
This is great information but I think your audio needs some tweaks. Everytime you take a breath and swallow I hear your spit. I feel like I'm watching ASMR XD
agreed, it makes really hard to listen to the video... put your mic farther from your mouth
God, how I hate javascript and all its children...