{"id":223,"slug":"dependency-injection","name":"Dependency injection","short_description":"Dependency injection separates the depndency's implementation from the class that's using it by passing it in from outside.","url":"https://github.com/topics/dependency-injection","github_count":7514,"created_by":"Martin Fowler","logo_url":null,"released":"January 23, 2004","wikipedia_url":"https://en.wikipedia.org/wiki/Dependency_injection","related_topics":["separation-of-concerns","loose-coupling","dependency-inversion-principle","inversion-of-control","constructor-injection","service-locator-pattern","dependency-injection-container"],"aliases":["dependency-injection-pattern"],"github_url":null,"content":"\u003cp\u003e\u003cstrong\u003eDependency injection\u003c/strong\u003e (\u003cstrong\u003eDI\u003c/strong\u003e) is an implementation of the \u003ca href=\"/topics/dependency-inversion-principle\"\u003edependency inversion principle\u003c/a\u003e with the aim of \u003ca href=\"/topics/separation-of-concerns\"\u003eseparation of concerns\u003c/a\u003e by separating the depndency’s implementation from the class that’s using it. That kind of abstraction makes it possible to have different implementations with the same public methods so the class using it, doesn’t need to care which of the implementations is used. This is also especially useful for \u003ca href=\"/topics/unit-testing\"\u003eunit testing\u003c/a\u003e.\u003c/p\u003e\n\n\u003cp\u003eThere are different types of dependency injection:\u003c/p\u003e\n\u003cul\u003e\n  \u003cli\u003e\u003ca href=\"/topics/constructor-injection\"\u003econstructor injection\u003c/a\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"/topics/setter-injection\"\u003esetter injection\u003c/a\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"/topics/interface-injection\"\u003einterface injection\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n","created_at":"2024-07-29T13:37:01.812Z","updated_at":"2026-06-28T00:08:09.886Z","topic_url":"https://awesome.ecosyste.ms/api/v1/topics/dependency-injection","html_url":"https://awesome.ecosyste.ms/topics/dependency-injection","projects_url":"https://awesome.ecosyste.ms/api/v1/projects?keyword=dependency-injection","lists_url":"https://awesome.ecosyste.ms/api/v1/lists?topic=dependency-injection"}