File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -408,7 +408,7 @@ abstract class GetIt {
408
408
/// provide a [disposingFunction] . This function overrides the disposing
409
409
/// you might have provided when registering.
410
410
FutureOr resetLazySingleton <T extends Object >({
411
- Object ? instance,
411
+ T ? instance,
412
412
String ? instanceName,
413
413
FutureOr Function (T )? disposingFunction,
414
414
});
Original file line number Diff line number Diff line change @@ -1034,7 +1034,7 @@ class _GetItImplementation implements GetIt {
1034
1034
/// provide a [disposingFunction]
1035
1035
@override
1036
1036
FutureOr resetLazySingleton <T extends Object >({
1037
- Object ? instance,
1037
+ T ? instance,
1038
1038
String ? instanceName,
1039
1039
FutureOr Function (T )? disposingFunction,
1040
1040
}) async {
Original file line number Diff line number Diff line change @@ -509,6 +509,24 @@ void main() {
509
509
GetIt .I .reset ();
510
510
});
511
511
512
+ test ('reset LazySingleton by instance only' , () {
513
+ // Arrange
514
+ final getIt = GetIt .instance;
515
+ constructorCounter = 0 ;
516
+ getIt.registerLazySingleton <TestClass >(() => TestClass ());
517
+ final instance1 = getIt.get <TestClass >();
518
+
519
+ // Act
520
+ GetIt .I .resetLazySingleton (instance: instance1);
521
+
522
+ // Assert
523
+ final instance2 = getIt.get <TestClass >();
524
+ expect (instance1, isNot (instance2));
525
+ expect (constructorCounter, 2 );
526
+
527
+ GetIt .I .reset ();
528
+ });
529
+
512
530
test ('unregister by instance when the dispose of the register is a future' ,
513
531
() async {
514
532
final getIt = GetIt .instance;
You can’t perform that action at this time.
0 commit comments