Skip to content

Issue #179 ignore instanceName looking for a factory #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/get_it_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ class _GetItImplementation implements GetIt {

for (final type in dependsOn!) {
final dependentFactory =
_findFirstFactoryByNameAndTypeOrNull(instanceName, type);
_findFirstFactoryByNameAndTypeOrNull(null, type);
throwIf(dependentFactory == null,
ArgumentError('Dependent Type $type is not registered in GetIt'));
throwIfNot(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: get_it
description: Simple direct Service Locator that allows to decouple the interface from a concrete implementation and to access the concrete implementation from everywhere in your App"
version: 6.1.1
version: 6.1.2
maintainer: Thomas Burkhart (@escamoteur)
authors:
- Flutter Community <[email protected]>
Expand Down
16 changes: 16 additions & 0 deletions test/async_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,22 @@ void main() {
expect(instance, const TypeMatcher<TestClass>());
});

test('Register singleton with dependency and instanceName', () async {
final getIt = GetIt.instance;
await getIt.reset();
getIt.registerSingletonAsync<TestClass>(
() async => TestClass(internalCompletion: false),
);

getIt.registerSingletonAsync<TestClass2>(
() async => TestClass2(internalCompletion: false),
instanceName: "test2InstanceName",
dependsOn: [TestClass]);

await getIt.allReady();
expect(getIt.get<TestClass2>(instanceName: "test2InstanceName"), isA<TestClass2>());
});

test('Code for ReadMe', () async {
final sl = GetIt.instance;

Expand Down