Описание тега inject
Synonym for Dependency Injection
Dependency injection (DI) is a design pattern for object-oriented programming involving dynamically injecting (inserting) into a software component dependencies (service components) that it needs to function, without needing the dependent component to hard-code a dependency on the service. This reduces coupling between the dependent consumer and the service.
Resources / background questions
If you need a general introduction to DI you should refer to this question: What is dependency injection?
If you need a non-technical introduction you can refer to this question: How to explain Dependency Injection to a 5-year old.
If you would like to understand the relationship between DI and Inversion of Control (IoC), see Inversion of Control < Dependency Injection.
For book recommendations see Dependency Injection book recommendation(s)(dead link).
For general recommendations for writing DI-friendly code without a DI Container, see Dependency Inject (DI) “friendly†library.
If you are wondering why you should use a DI Container instead of Poor Man's DI, see Why do I need an IoC container as opposed to straightforward DI code?
If you are wondering what the Composition Root is, see /questions/2552426/chto-takoe-koren-kompozitsii-v-kontekste-vnedreniya-zavisimostej.
For potential downsides of using DI, see /questions/10120858/kakovyi-nedostatki-ispolzovaniya-inektsij-zavisimosti
Dependency injection and Inversion of Control are closely related. The difference between them is discussed at /questions/20987318/gde-imenno-raznitsa-mezhdu-ioc-i-di.
Also can read basic here: Dependency Injection For Beginner - 1
Related Patterns