Skip to content

Object/factory with with name __environments__ and type Set<String> is already registered inside GetIt. #124

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
Pawelo93 opened this issue Oct 23, 2020 · 7 comments

Comments

@Pawelo93
Copy link

Hello

Im using two configuration of getIt, one in main project and one in other module. When both configurations meet, there is error:
Object/factory with with name __environments__ and type Set<String> is already registered inside GetIt.

It was working before on older version.

@escamoteur
Copy link
Collaborator

What do you mean with two configurations?
can you show me a bit more of your code?

@Pawelo93
Copy link
Author

Pawelo93 commented Oct 23, 2020

  configureModuleInjection(moduleGetIt, Environment.dev);
  configureMainInjection(mainGetIt, Environment.dev);

im trying to join two separate DI, in mainGetIt i need one class from module with all it dependencies

@Pawelo93
Copy link
Author

Sorry I was missing
GetIt.asNewInstance()

@ReniDelonzek
Copy link

I have same problem. My code

    if (!GetIt.I.isRegistered(instance: HiveService())) {
      GetIt.I.registerSingleton<HiveService>(HiveService());
    }

isRegistered always returns false, and the second time I run this code, registerSingleton fails saying that this class is already registered

My get_it version: 5.0.1

@escamoteur
Copy link
Collaborator

@ReniDelonzek No, you have another problem :-)

What you are doing here

isRegistered(instance: HiveService()))

is that you create a completely new HiverService object and you ask GetIt if this is already registered, which never can be the case to this if always evaluate to true.
Using the instance parameter is when you want to know if an object you have is registered.
What you want todo is:

GetIt.I.isRegistered<HiveService>();

But I also would question why do you check this at all? Maybe there is a better approach.

Cheers

@ReniDelonzek
Copy link

GetIt.I.isRegistered<HiveService>();

Oh, it is work!

Sorry, my first use this lib, Alias, congratulations on the excellent work done on it!

My use case is as follows:
I have a function that is triggered by Firebase's onBackgroundMessage, so it runs in a new isolate.

The code that I run next depends on this service being registered correctly in GetIT. And as it is a new isolate, I have to register inside it

In this situation I have no way of knowing when this code is running for the first time (which would be the only time I need to register), so this conditional to know if it is already registered or not.

If you have any suggestions for a better approach that I can take, please, I would greatly appreciate receiving. Thank you!

@escamoteur
Copy link
Collaborator

escamoteur commented Oct 28, 2020 via email

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

3 participants