Skip to content
Commitwise
Menu

Composition root

The one place at the top of an app where the real dependencies are created and connected.

Definition

Everything else receives its dependencies instead of creating them, so swapping implementations (fakes for tests, previews or UI tests, different environments) means changing only the composition root. In a SwiftUI app it is usually the App struct; in an Android app with Hilt, the DI modules play this role.

In practice

RecipesApp creates AppDependencies.live(), or fakes when launched with --ui-testing, and passes them to the first screen.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.