Even though this is 3 years old the knowledge being explained is as current as yesterday. I'm going to need to watch this whole thing a couple of times because there's a ton of useful intrinsic understanding being rapidly but coherently presented that makes the other DI frameworks more understandable. A Belated THANKS!
Awesome stuff! I've started out in the IT world, less than a year ago, with videos from KudVenKat, for real beginners. But yours, are on a whole different level. I apreciate them very much. Also, I never thought that twich is used for anything other than games. :D GG!
Eyyy thanks man, and yeah I stream working on personal projects, where I can answer questions and talk with viewers, come join i post updates on discord)
Great work as always, tnx a lot i literally watched more than 5 hour worth of time videos about DI so i can grasp the full picture your video connected all the dots that i had. i'm looking forward for your MVC content that you mentioned at the end of this video.
This tutorials are the real deal truly..like your making tutorials and explaining things in a way I would explain them to someone if I knew these topics haha Your explonations truly give you insight into topics, not just another abstractions to get by I think that this is what happens when you are truly passionate or have read some masterpieces (SICP shhh) 😉
Hi @Raw Coding, thanks for the video. 1. Could you please elaborate on the scenario when the constructors of the services require some kind of data (authentication, etc.). So how would the static class Activator handle that while resolving? How is that handled in real world applications? 2. A mention about other types of DI would have been helpful (not just using constructors) - Being a bit exhaustive about the possibilities/ variants.
1. Just had a look at the MVC video in one of your playlists. I think the reflected data can be parsed after a check (binding?) (using System.Type class)
If the service requires authentication, that service would have the httpcontext injected in to it, or some kind other service that loads authentication from the httpcontext and persists it through the scope. On point 2 - you can use reflection to assign things to fields or properties or in to functions.
Amazing Video, Nice explanation bro. Thank you for making the concepts clear. I This contents helps for the people who are new and starting to learn the programming and concepts associated with it.
I am trying to wrap my head around the GetService method. Please tell me if my summary is right. Resolves the service. Using recursion. We want to resolve the service until it has no parameters. It essentially uses recursion to create necessary services starting from the ones that don't require parameters and use that to create another service in the chain until required service is generated.
First off, awesome video! Couple questions. Can you briefly describe (or point me to some resources) describing why we needed to pass the Activator.CreateInstance as a delegate to the CreateImplementation method. Also, I understand that this isn’t production ready code, but with the Transient dependencies, wouldn’t the reference to the instance exist for the lifetime of the container. If an application creates multiple instances, they’d never actually get released /garbage collected. Am I understanding that correctly?
So I’ve just used an abstract factory pattern there without an interface and the factory is just a function (well in c# delegates are object but anyway) you want to look for abstract factory pattern. As I understand it the application has 1 DI container so as soon as the service that consumes a transient service is disposed of the transient service is disposed as well. Otherwise we would run out of memory eventually.
Thnx for good explanation of creation of custom DI container. Can you use classic VS for coding - easier to migrate via code due to familiar interface?
41:32 Awesome, but I see one flaw, if I am correct. If I try to create an implementation of an class Foo as singleton with a ctor Foo(Bar b), then every time, Bar b is resolved.
Thanks for the video really helpful. Hey, just wondering if it'd make any sense to do this for MVVM in terms of injecting the services into view models. I get that there's MVVM frameworks out there that handle this sort of things just wondering if this is roughly the way they'd handle it?
Cheers, MVVM is MVC but you have the additional VM (view model) basically mapping between your data and what you want to display. There should be no need to do dependency injection when you do the mapping. View Model is a dumb object, just data representation, same as the Model. Only the controller has functions and has services injected to do stuff to the models.
Thanks for replying the problem is , when we register we register and interface , so when getservice the list in the container containes the interface , the predicate that evaluate abd return the dependency, the change need to be done there right ?
I lost understanding from the part where you add the parameter in the container. I will repeat and again try to understand. This dependency injection is complicated or I think you have gone a bit complex on trying to build a generic application which will be compatible with any type. I will not give up to give effort to understand.
the container contains types that it knows how to create, if 1 type requires other types to be created, the container needs to know about those required types and how to inject them.