File tree Expand file tree Collapse file tree 2 files changed +1
-38
lines changed Expand file tree Collapse file tree 2 files changed +1
-38
lines changed Original file line number Diff line number Diff line change @@ -41,26 +41,14 @@ class GetIt {
41
41
static GetIt get I => instance;
42
42
43
43
/// You should prefer to use the `instance()` method to access an instance of [GetIt] .
44
- /// If you really, REALLY need more than one [GetIt] instance please set allowMultipleInstances
45
- /// to true to signal you know what you are doing :-).
46
44
factory GetIt .asNewInstance () {
47
- throwIfNot (
48
- allowMultipleInstances,
49
- StateError (
50
- 'You should prefer to use the `instance()` method to access an instance of GetIt. '
51
- 'If you really need more than one GetIt instance please set allowMultipleInstances to true.' ),
52
- );
53
45
return GetIt ._();
54
46
}
55
47
56
48
/// By default it's not allowed to register a type a second time.
57
49
/// If you really need to you can disable the asserts by setting[allowReassignment] = true
58
50
bool allowReassignment = false ;
59
-
60
- /// By default it's not allowed to create more than one [GetIt] instance.
61
- /// If you really need to you can disable the asserts by setting[allowReassignment] = true
62
- static bool allowMultipleInstances = false ;
63
-
51
+
64
52
/// retrieves or creates an instance of a registered type [T] depending on the registration function used for this type or based on a name.
65
53
T get <T >([String instanceName]) {
66
54
throwIfNot (
Original file line number Diff line number Diff line change @@ -105,31 +105,6 @@ void main() {
105
105
GetIt .I .reset ();
106
106
});
107
107
108
- test ('register lazy singleton two instances of GetIt' , () {
109
- GetIt .allowMultipleInstances = true ;
110
- var secondGetIt = GetIt .asNewInstance ();
111
-
112
- constructorCounter = 0 ;
113
- GetIt .instance.registerLazySingleton <TestBaseClass >(() => TestClass ());
114
- secondGetIt.registerLazySingleton <TestBaseClass >(() => TestClass ());
115
-
116
- var instance1 = GetIt .I <TestBaseClass >();
117
-
118
- expect (instance1 is TestClass , true );
119
-
120
- var instance2 = GetIt .I .get <TestBaseClass >();
121
-
122
- expect (instance1, instance2);
123
- expect (constructorCounter, 1 );
124
-
125
- var instanceSecondGetIt = secondGetIt.get <TestBaseClass >();
126
-
127
- expect (instance1, isNot (instanceSecondGetIt));
128
- expect (constructorCounter, 2 );
129
-
130
- GetIt .I .reset ();
131
- });
132
-
133
108
test ('trying to access not registered type' , () {
134
109
var getIt = GetIt .instance;
135
110
You can’t perform that action at this time.
0 commit comments