Skip to content
loading...

How YOU can Learn Dependency Injection in .NET Core and C#

Chris Noring on November 28, 2019

Follow me on Twitter, happy to take your suggestions on topics or improvements /Chris This is an intro to Dependency Injection, also called DI. I ... [Read Full]
markdown guide
 

Hi Chris.
Excellent Post. Thank you.
I have a question => you mentioned " it makes sense to use when you have a mutable state and it's important that the service consumer gets their own copy of this service." can you explain what that means and also explain how that work with other scopes like Scoped and Singleton ?

 

hey.. so the whole idea of DI, at least in my mind is about three things 1) reuse services that are expensive to create 2) be able to share state. 3) make testing easier/code needs modification less seldom, you rely on contracts, i.e Interfaces Singleton pattern is a clear case where we can share state. Because it's created only once, you have fields on that service that you write to, e.g a CartService can be a singleton with an Items fields that you can keep adding items to and you can ensure that there are no more than one CartService created

 
 

Wonderful article on dependency injection

Just a small question?
The heading says
Create an interface IProductsController
And the code actually created is IProductService, it the heading a typo?

 
 

Loved the article! I found a small typo for correction in the controller:

private readonly _shippingService IShippingService;

 

Thanks, Michael, glad you liked it. Appreciate the typo correction as well :)

 
 

Thanks for the article. The last link at the beginning routes to a 404 pages.

 

hi Peter. Thanks for that. The link should be fixed now

 

Seriously, First article that finally got me to understand Dependency Injection!

(BTW, you need to fix your 'e' key. It's missing in many places. Are you using one of those Mac laptops?)

 

thanks. and yes my Mac has seen better days :)

code of conduct - report abuse