Skip to content

[ERROR] isReady and dependsOn not working as expected #163

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
tomasweigenast opened this issue Feb 24, 2021 · 8 comments
Closed

[ERROR] isReady and dependsOn not working as expected #163

tomasweigenast opened this issue Feb 24, 2021 · 8 comments

Comments

@tomasweigenast
Copy link

Hello. I'm using get_it to manage some dependencies on my project.

I have two models: Storage which has an async method called init which creates folders and so on. Another model called Worker relies on Storage to get a path to a folder, so, Storage MUST load before.
This is my code:

// Register Storage
GetIt.instance.registerSingletonAsync(() async {
    var storage = Storage();
    await storage.init();
    return storage;
});

// Register worker
GetIt.instance.registerSingletonAsync(() async {
    var worker = Worker();
    await worker.load();
    return worker;
}, dependsOn: [Storage]);

I put some debug messages to see what is happening:

[LOG] Trying to load Worker...
[LOG] An exception occurred: HiveError: You need to initialize Hive or provide a path to store the box. // This error happens because Storage hasn't loaded and Hive does not know where to store everything.

[LOG] Storage has been loaded.

It is not supposed to load Storage first?

@tomasweigenast tomasweigenast changed the title isReady and dependsOn not working as expected [ERROR] isReady and dependsOn not working as expected Feb 24, 2021
@escamoteur
Copy link
Collaborator

Are you sure you initialize Hive correctly?
this should work.
Can you show we where you use isReady? too?

@tomasweigenast
Copy link
Author

@escamoteur As I said, Hive cannot be initialized correctly because Storage is not initialized before so it does not know where to initialize Hive

@escamoteur
Copy link
Collaborator

And Worker initilizes Hive?

@tomasweigenast
Copy link
Author

tomasweigenast commented Feb 25, 2021 via email

@escamoteur
Copy link
Collaborator

Would it be possible to clone your project so that I can take a closer look? that should definitely work

@tomasweigenast
Copy link
Author

tomasweigenast commented Feb 25, 2021 via email

@escamoteur
Copy link
Collaborator

That may be but if you check the async tests of get_it this should work. Best to create a small repro project with just the Storage/Worker class.

@escamoteur
Copy link
Collaborator

Any updates on this?

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