Recipes

Override a production graph in tests

Create a child Scope with explicit substitutions while keeping the production container immutable.

v0.1.0-dev.1Intermediateark_di

Override a production graph in tests

Build one container per test or create a child from a reusable parent configuration. Override the dependency and any parent Singleton that has already captured it.

dart
final testScope = production.createChild((binder) {
  binder.bindInstance<Clock>(fakeClock, overrideParent: true);
  binder.bindLazySingleton<Scheduler>(
    (resolver) => Scheduler(resolver.get<Clock>()),
    overrideParent: true,
  );
});

Always close the child in test cleanup. A test substitution should not mutate the production registration table.

ARKTELOS

Purpose-built engineering systems for software that has to hold.