Use code DEPS for 20% off (first 50 people): 🤍nickchapsas.com/p/from-zero-to-hero-dependency-injection-in-net Become a Patreon and get Discord & source code access: 🤍🤍patreon.com/nickchapsas Check out my courses: 🤍nickchapsas.com Hello everybody I'm Nick and in this video I will introduce you to, hopefully, a few dependency injection methods for the built in IoC container that you might not know about. Some of the names can be deceiving so once you finish watching this video you should know everything you need to write some awesome IoC code. Don't forget to comment, like and subscribe :) Social Media: Follow me on GitHub: 🤍bit.ly/ChapsasGitHub Follow me on Twitter: 🤍bit.ly/ChapsasTwitter Connect on LinkedIn: 🤍bit.ly/ChapsasLinkedIn Keep coding merch: 🤍keepcoding.shop #csharp #dotnet #dependencyinjection
I am using .NET DI for years and this video still has a hell of things I did not even know to exist. Thanks
Dude why are you not on Udemy?
Singleton/transient/scoped all refer to the lifetime of the implementation, not to the amount of implementations for a abstraction! Consider the fact that you can register both a singleton and transient for the same abstraction and it still works as expected: the singleton is shared and the transient is unique for each branch of the object graph. Even if they are delivered behind a IEnumerable. This technique Nick is showing is incredibly powerful coupled with the strategy pattern. Keep up the good work Nick, love your videos! Great length and very focused.
I'm still not sure what's the better way to wire things together - the explicit model (as seen in the video) or the annotation- and classpath-scanning driven approach used by Spring Boot. I've used both extensively, and saw success (and failure) with both.
This is the cli dependency injection command you ain't using but should be: "dotnet add package Autofac"
What is the highlighter you use to draw rectangle and points on the screen
Horrible. When I moved from .net to Java Spring, all these nightmares disappeared. Explicit stupid constructors? Lombok. Component registration? Single attribute. (annotation). All the mentioned things cleverly handled for you.
Are a good guitar player?😁
will that behavior of tryaddsingleton will not change on the future? because all I know is MS has unsettling minds and changes anything that has some breaking changes.
Nice and useful video, thanks!
and now tell me how to implement dependency injection without the frustrating need to specify the type i want to register 3 times!
1st as a private readonly, 2nd as constructor parameter 3rd as an assignemnt in the constructor body
i hoped c#11 would have a revelation for that...
this is so annoying, you know what i'm doing now? i'm actually converting all my classes to records, just to get rid of the constructor which is basically abusing the whole thing XD
but it works and there is no performance or memory downside so ... who cares. abusing rules
Huh, the .Net DI container is really odd in it's opinions. I'd consider nearly everything in this video bad practice, but the thing I use all the time (Decoration) isn't supported by design. I guess I'll just keep shimming in SimpleInjector until the .NET DI container actually supports decorators.
Nice video thank !
What keyboard are you using ? I have changed for a Logitech MX Key mini but I have lost so much dexterity ...
Dependency injection is awesome! 👍 The company I work for, use it very well.
FOLKS, you should learn it!
Nick, I really like your videos content-wise, but you are talking way too fast. English is not my first language and I find it difficult to follow sometimes.
I can't figure out when you would want to register more than one implementation of a given interface. If anyone knows, I'm curious about that.
Is there a way to override the instance used in the DI container?
In Unity I believe that there is something called DependencyOverride, where you can supply the instance yourself effectively overriding what's already registered with the container?
That would be useful.
Holy crap this is ugly. C# > Java propaganda is real