runWithIoc<T> function
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});