DEV Community

HelpMichaelCode
HelpMichaelCode

Posted on

Dependency Injection

I can’t seem to get my head around dependency injection in ASP .Net Core.. Like I know what it is but I can’t seem to think of a simple use case for it in my head. Can someone give like a simple example? Plus, it mentioned that whenever you’re injecting a dependency, you shouldn’t use the ‘new’ keyword but instead pass it into a constructor. Why?

Top comments (1)

Collapse
 
helpmichaelcode profile image
HelpMichaelCode

Hi Andy, thanks for replying. I think I get it.. but you can always use a method to return an object and test it that way no?