In the first article in this series, I explained my motivation for wanting to do dependency injection inspired by the Cake Pattern in Kotlin (and other languages without self-types), despite the known issues with that style of coding. I presented a way of doing so that I believe will allow programmers to keep the good things from the Cake, while avoiding some of the problems. The examples in that article, however, were extremely small. Let’s create a (slightly) bigger one and look at some more code.
This article is about how to do dependency injection without frameworks in Kotlin, but let’s start out discussing Scala. Since 2009, a small but highly successful team at Knowit has been delivering solutions to one of our customers using Scala as their backend programming language. More than 20 such applications are currently in production. The team has seen major changes to its composition every year, with people joining and leaving. To date, about 35 contributors have worked on the projects, meaning that an average of about 3 people have had to learn to work with the tech stack in use every year. To make things even more difficult, almost no one has had prior knowledge of Scala before joining the team, and more than half have joined the team straight out of university.