Some people say that it is better to use dependency injection. Why is that?
I think it is better to have few global, easy accessible classes, rather than huge constructors.
Does it influence application speed in any way?
Mix of these two would be probably the best.
The main advantage will be decoupling, which will help with unit testing. This sort of depends entirely on how you code these “easily accessible classes”.
The idea is this. A class decouples from implementation (
class) dependencies by only having a dependency on the contract (interface). In your live environment you may never provide a new implementing class, but in your test environment you very likely will (be it a handmade stub, or a mocked class from a mocking framework).Application speed would need profiling, but the use of a framework for DI would likely incur some overhead instead of you talking directly to a singleton that you know about. The important question: is this overhead a problem? Only performance expectations and profiling can tell you that. In my experience, the benefits far outweigh the negligible performance detriment.