Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my first .net core application. Dependency Injection is all about not newing up classes in the application, but rather injecting them at one place so that they're easily changeable, right? But I can see that I'm quickly going to have so many (possibly hundreds) of repository services and other being injected into my application. Is this normal?

What I have tried:

Tried nothing, just an observational question.
Posted
Updated 26-May-20 3:43am

1 solution

DI tries to decouple the interface from the implementation so you can swap classes out, but in the real world that rarely happens. The biggest advantage is to allow unit testing as you can replace things with mocked versions of the services as needed.

As for it being normal to have loads of registrations, yes it is. Some DI frameworks let you do registration by configuration so if you have a bunch of "IMyService" and "MyService" items it can auto marry them up, but from my experience it is generally preferred to explicitly declare the registrations as needed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900