The .NET dependency injection methods you are not using

preview_player
Показать описание

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:

#csharp #dotnet #dependencyinjection
Рекомендации по теме
Комментарии
Автор

Thank you for this, I finally understand why my multitenancy configuration wasn't working as expected 😂

winstonstrongarm
Автор

This came at a perfect time for me! I've been working on a shared library that uses DI, which has dependencies on other objects being registered, so we want to register defaults but have them be overrideable. Thanks for the great explanation!

DevonLehmanJ
Автор

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.

ericvruder
Автор

I am using .NET DI for years and this video still has a hell of things I did not even know to exist. Thanks

lasindunuwanga
Автор

My favorite part of this is how concise and straightforward this implementation of DI is, and how you can tell exactly what your code is doing just by looking at it.

alexanderkvenvolden
Автор

A bit fast explained for the level I'm at.
BUT... I really like the way you explain it. So, I subscribed to the channel.

ltl
Автор

straight to the point, no bs, fantastic!

zhangboyangsir
Автор

Had this requirement years ago and what I did is a trhough a factory and some custom hack way of doing this, I wish I had seen this before, this really is great find! Thanks Nick!

santilmo
Автор

Just wish I can like each of your videos 1billion times.
I have learnt a lot from you.
Thanks.

Aweklin
Автор

I discovered those overloads while building reusable libraries. Very helpful because you don't want the end user of the library to accidentally register the same service multiple times.

astralpowers
Автор

Dependency injection is awesome! 👍 The company I work for, use it very well.

FOLKS, you should learn it!

swedishprogrammer
Автор

Thanks for this video. I like it because I use the built in dependcency injection in a lot of projects.

xavier.xiques
Автор

Yep that's not obvious behaviour ! Thanks Nick keep up the good work

dakotapearl
Автор

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.

AlanDarkworld
Автор

Also sounds a lot as a "works by an accident" type of scenario :D

PetrVejchoda
Автор

Very intresting video, what's the annotation tool you use btw?

davidrodriguezlagrana
Автор

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.

MagnusSydoff
Автор

This mess is why I prefer Simple Injector. Simple Injector fails early if you try to add multiple implementations for the same service. Unless that's specifically what you want to do of course, in which case there's a separate method for that. This way there won't be any nasty surprises down the road.
Also the fact that Simple Injector can (and by default will) Verify its container registrations is 👌💯

omarjuul
Автор

How properly resolve the different implementations of the common type?

danku
Автор

I was hoping for some cool way to distinguish which `IService` is injected which would be far more interesting IMHO since you can have few `IService` implementations for lets say authentication, authorization, translation etc. . I'm currently in that situation where I have to register multiple `IService` with different implementations and then use factories to determine which ones to load and when and ... I'm not gonna lie, it's a fking pain in the ass to create all of those factories, checks, guards etc.
If you know any way to improve this kind of chaos I would be greatly interested in seeing it.

Thanks for making these videos and keeping it informative

mrogalski