Writing our code

We will create an application that can read from a database data about people, classes, and who has signed up to which classes. We will have a user service which will implement some simple business logic with the data, and a service that will access the data. It will be a small application, but it will clearly show how dependency injection works.

Let's start with the simple stuff. We will need to have a model for the objects that we will be representing:

case class Class(id: Int, name: String)case class Person(id: Int, name: String, age: Int)

In the preceding code, we have two classes that will be used in our application. There is nothing special about them, so let's go further.

We said that we want our application to be ...

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.