Chapter 2. Creating services
This chapter covers
- Instantiating service objects
- Injecting and validating dependencies and configuration values
- Promoting optional constructor arguments to required ones
- Making implicit dependencies explicit
- Designing services to be immutable
In the following two chapters, we’ll discuss different types of objects and the guidelines for instantiating them. Roughly speaking, there are two types of objects, and they both come with different rules. In this chapter we’ll consider the first type of objects: services. The creation of other objects will be the topic of chapter 3.
In an application there will typically be two types of objects:
- Service objects that either perform a task or return a piece of information
- Objects that will hold some data, and optionally expose some behavior for manipulating or retrieving that data