Skip to content

Commit 4eaafb1

Browse files
authored
Merge pull request #30 from anaisbetts/patch-1
Remove allowMultipleInstances
2 parents 43afac6 + a5ed4d8 commit 4eaafb1

File tree

2 files changed

+1
-38
lines changed

2 files changed

+1
-38
lines changed

lib/get_it.dart

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,14 @@ class GetIt {
4141
static GetIt get I => instance;
4242

4343
/// 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 :-).
4644
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-
);
5345
return GetIt._();
5446
}
5547

5648
/// By default it's not allowed to register a type a second time.
5749
/// If you really need to you can disable the asserts by setting[allowReassignment]= true
5850
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+
6452
/// retrieves or creates an instance of a registered type [T] depending on the registration function used for this type or based on a name.
6553
T get<T>([String instanceName]) {
6654
throwIfNot(

test/get_it_test.dart

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,31 +105,6 @@ void main() {
105105
GetIt.I.reset();
106106
});
107107

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-
133108
test('trying to access not registered type', () {
134109
var getIt = GetIt.instance;
135110

0 commit comments

Comments
 (0)