@@ -1352,12 +1352,23 @@ class _GetItImplementation implements GetIt {
1352
1352
);
1353
1353
_pushScopeInProgress = true ;
1354
1354
_scopes.add (_Scope (name: scopeName, disposeFunc: dispose));
1355
- init? .call (this );
1356
- if (isFinal) {
1357
- _scopes.last.isFinal = true ;
1355
+ try {
1356
+ init? .call (this );
1357
+ if (isFinal) {
1358
+ _scopes.last.isFinal = true ;
1359
+ }
1360
+ onScopeChanged? .call (true );
1361
+ } catch (e) {
1362
+ final failedScope = _scopes.last;
1363
+
1364
+ /// prevend any new registrations in this scope
1365
+ failedScope.isFinal = true ;
1366
+ failedScope.reset (dispose: true );
1367
+ _scopes.removeLast ();
1368
+ rethrow ;
1369
+ } finally {
1370
+ _pushScopeInProgress = false ;
1358
1371
}
1359
- onScopeChanged? .call (true );
1360
- _pushScopeInProgress = false ;
1361
1372
}
1362
1373
1363
1374
bool _pushScopeInProgress = false ;
@@ -1395,12 +1406,24 @@ class _GetItImplementation implements GetIt {
1395
1406
);
1396
1407
_pushScopeInProgress = true ;
1397
1408
_scopes.add (_Scope (name: scopeName, disposeFunc: dispose));
1398
- await init? .call (this );
1399
- if (isFinal) {
1400
- _scopes.last.isFinal = true ;
1409
+ try {
1410
+ await init? .call (this );
1411
+
1412
+ if (isFinal) {
1413
+ _scopes.last.isFinal = true ;
1414
+ }
1415
+ onScopeChanged? .call (true );
1416
+ } catch (e) {
1417
+ final failedScope = _scopes.last;
1418
+
1419
+ /// prevend any new registrations in this scope
1420
+ failedScope.isFinal = true ;
1421
+ await failedScope.reset (dispose: true );
1422
+ _scopes.removeLast ();
1423
+ rethrow ;
1424
+ } finally {
1425
+ _pushScopeInProgress = false ;
1401
1426
}
1402
- onScopeChanged? .call (true );
1403
- _pushScopeInProgress = false ;
1404
1427
}
1405
1428
1406
1429
/// Disposes all factories/Singletons that have been registered in this scope
@@ -1756,9 +1779,6 @@ class _GetItImplementation implements GetIt {
1756
1779
outerFutureGroup.close ();
1757
1780
});
1758
1781
1759
- /// outerFutureGroup.future returns a Future<List> and not a Future<T>
1760
- /// As we know that the actual factory function was added last to the FutureGroup
1761
- /// we just use that one
1762
1782
serviceFactory.pendingResult =
1763
1783
outerFutureGroup.future.then ((completedFutures) {
1764
1784
return serviceFactory.instance! ;
0 commit comments