Skip to main content

Posts

Showing posts from September, 2019

Dependency Injection: A General Principle For All Software Developers

Introduction Dependency injection, often shortened to the acronym DI, is a fundamental principle of software design. Every software developer makes decisions related dependency injection whether they are aware of it or not, and most, if not all developers, have had to deal with the consequences of poor DI-related decisions in an existing code base. Understanding it and deciding when and how to use it is crucial to building good software. In this article, we define DI, discuss its purpose and benefits, and when and when not to use it. By learning these principles, we can write higher-quality, more maintainable code and even ship code faster. This article uses the Java programming language for examples. The general principles of DI, however, apply to any general-purpose programming language. Definition of DI Dependency injection is the act of providing dependencies to code. The opposite of dependency injection is to have code explicitly  access its dependencies via global va...