Skip to content

isRegistered always returns false #117

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
eelishiram opened this issue Oct 14, 2020 · 2 comments
Closed

isRegistered always returns false #117

eelishiram opened this issue Oct 14, 2020 · 2 comments

Comments

@eelishiram
Copy link

eelishiram commented Oct 14, 2020

Hi. I am using get_it version 5.0.1 and I have a snippet like this

final locator = GetIt.instance;

check() {
  Test a = Test();
  locator.registerFactory<Test>(() => a);
  Test b  = locator.get<Test>();
  print(identical(a, b)); // true
  print(locator.isRegistered<Test>(instance: b)); // false
}

As you can see, the identical returns true for instances a and b. However, when I try to check whether the instance b is registered, it returns false. If I modify the last print statement as below

print(locator.isRegistered<Test>()); // true

then it does return true. But since I want to check if exact instance is registered or not, this does not suit my needs at all. Is there something that I am missing regarding to the usecase of instance field?

@escamoteur
Copy link
Collaborator

don't pass the instance that does only work for singletons, not for factories

@escamoteur
Copy link
Collaborator

did this solve your problem? I will close this for now. if you still have a problem please open a new issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants