DEV Community


Dependency Injection

helpmichaelcode profile image HelpMichaelCode ・1 min read

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?

Discussion (3)

Editor guide
helpmichaelcode profile image
HelpMichaelCode Author

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?