runWithIoc<T> function

Future<T> runWithIoc<T>(
  1. IocContainer container,
  2. Future<T> body()
)

Runs body inside a Zone where ioc resolves to container.

The Zone is automatically discarded when body completes, leaving the global container untouched — no tearDown required.

test('my test', () async {
  final container = IocContainer()
    ..bind<LoggerContract>(() => MockLogger());

  await runWithIoc(container, () async {
    // ioc.resolve<LoggerContract>() returns MockLogger here
  });
});

Implementation

Future<T> runWithIoc<T>(IocContainer container, Future<T> Function() body) =>
    runZoned(body, zoneValues: {#iocContainer: container});