Member-only story
Google’s Wire: Automated Dependency Injection in Go
Building flexible and maintainable Go applications
Today, we will discuss something that many consider a fundamental principle of software engineering and programming in general: Dependency Injection. It’s always helpful to revisit first principles because they are well-proven and battle-tested, and have become industry standards.
This article will focus on Dependency Injection, specifically how to use DI in Go. By the end of the article, we will have a good understanding of why we should use DI, how to use it, and how Wire can save us a lot of time when configuring our dependencies.
What is Dependency Injection?
When we build software, we often break our code into smaller, isolated components that interact with each other to provide specific functionality. These components have relationships with each other, which we refer to as dependencies.
While managing dependencies at a small scale is relatively straightforward, as a software system grows, the dependency graph becomes increasingly complex. This can result in a big initialization block and make it difficult to break up code cleanly, especially when some dependencies are used multiple times. It can become tedious and time-consuming to make changes to…