4 Patterns for infrastructure dependencies

 

This chapter covers

  • Writing loosely coupled infrastructure modules using dependency patterns
  • Identifying ways to decouple infrastructure dependencies
  • Recognizing infrastructure use cases for dependency patterns

An infrastructure system involves a set of resources that depend on each other. For example, a server depends on the existence of a network. How do you know the network exists before creating a server? You can express this with an infrastructure dependency. An infrastructure dependency happens when a resource requires another one to exist before creating or modifying the first one.

Definition

An infrastructure dependency expresses a relationship in which an infrastructure resource depends on the existence and attributes of another resource.

Usually, you identify the server’s dependency on the network by hardcoding the network identifier. However, hardcoding more tightly binds the dependency between server and network. Anytime you change the network, you must update the hardcoded dependency.

In chapter 2, you learned how to avoid hardcoding values with variables to promote reproducibility and evolvability. Passing the network identifier as a variable better decouples the server and network. However, a variable works between resources only in the same module. How can you express dependencies between modules?

4.1 Unidirectional relationships

4.2 Dependency injection

4.2.1 Inversion of control

4.2.2 Dependency inversion

4.2.3 Applying dependency injection

4.3 Facade

4.4 Adapter

4.5 Mediator

4.6 Choosing a pattern