Global anti-injection dependency

Some people say it's better to use dependency injection. Why is this?

I think it's better to have several global, easily accessible classes, rather than huge constructors.

Does this affect application speed?

The mix of the two will probably be the best.

+3
source share
4 answers

The main advantage will be the decoupling, which will help with unit testing. It depends on how you code these "easily accessible classes".

. (class) , (interface). , , , ( ).

, DI, , , , . : ? . , .

+5

, static . - . .

?

, (Globals), . , Globals , .

, , DI - . .

+4

"globals" DI. , , , singleton . -. , , , . , . , , , , , , , , , . : , , :

  • ,
  • " ", , , .

DI - , , , , , .. , DI , , โ€‹โ€‹DI : DI ( , ), c omposition, .

+1

I think that at the top of this topic there is a very good summary of DI and how to use it correctly: Inject (DI) dependency "friendly" library

If you want to delve deeper into this topic, I can recommend Mark Siman's book, Dependency Injection in .NET.

+1
source

All Articles