Skip to content
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

Bug when trying to declare nested dependencies #9

Open
R9n opened this issue Jul 3, 2020 · 2 comments
Open

Bug when trying to declare nested dependencies #9

R9n opened this issue Jul 3, 2020 · 2 comments

Comments

@R9n
Copy link

R9n commented Jul 3, 2020

Hi.
I'm having trouble to do nested dependencies injection. I have a AppModule like this:


class Dependencies extends Module {
  Dependencies() {
    single(DioDart());
    single(JobsController(get()));  <===== here's the problem, the lib cant find DiotDart instance, but it has already declared above

    single(JobsService(get()));
    single(JobTypesServices());
    single(AuthServices());
    single(ServiceProvidersService(get()));
    single(UsersService());
  }
}

JobsController snippet:

  static String endpoint = '${apiURL}/jobs';
  DioDart dioDart;
  JobsController(this.dioDart);

Console error Stack (Debug mode):

[Easy Localization] Load asset from assets/i18n
I/flutter (21971): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (21971): │ #0   new InjectorIO.start (package:injectorio/src/io.dart:44:14)
I/flutter (21971): │ #1   MyApp.build (package:bridi_mobile/main.dart:47:16)
I/flutter (21971): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (21971): │ 🐛 Initiated InjectorIO in mode: InjectorMode.DEBUG
I/flutter (21971): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (21971): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (21971): │ #0   DefinitionRegistry._log (package:injectorio/src/bean_registry.dart:83:44)
I/flutter (21971): │ #1   DefinitionRegistry._showInstanceNotFound (package:injectorio/src/bean_registry.dart:91:7)
I/flutter (21971): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (21971): │ 🐛 InjectorIO:::	!!!--- Instance of type DioDart not found ---!!!
I/flutter (21971): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[Easy Localization] Build
[Easy Localization] Init Localization Delegate
[Easy Localization] Init provider

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following _Exception was thrown building MyApp(dirty, dependencies: [_InheritedProviderScope<ThemeController>]):
Exception: Instance of DioDart not found. Make sure you added
        it by using module or with [single()], [factory()] definition.

The relevant error-causing widget was: 
  MyApp file:///home/ark/Haizen/projetox/bakcup/bridi-mobile/lib/main.dart:34:18
When the exception was thrown, this was the stack: 
#0      DefinitionRegistry.get (package:injectorio/src/bean_registry.dart:60:7)
#1      get (package:injectorio/src/component_binder.dart:22:24)
#2      get (package:injectorio/injectorio.dart:9:15)
#3      new Dependencies (package:bridi_mobile/main.dependencies.dart:14:27)
#4      MyApp.build (package:bridi_mobile/main.dart:47:31)
...
════════════════════════════════════════════════════════════════════════════════════════════════════
@pedromassango
Copy link
Contributor

Hi, thanks for filling this issue.

As stated in the documentation, you need to use inject() when you want to resolve a dependency inside a Module. Please let me know if this helps solve your problem.

@R9n
Copy link
Author

R9n commented Jul 7, 2020

Hi, thanks for answer.
Then i've tried what is in the example but stiil not working :(
Take a look in what i'm doing:

ImageHandler class

  ImagesHandler(this.imagePicker);
  ImagePicker imagePicker;
  Future<void> getImage(ImageSource imageSource) async {
    return await imagePicker.getImage(source: imageSource);
  }
}

Dependences module

class Dependencies extends Module {
  Dependencies() {
    single(ImagePicker());
    single(ImagesHandler(inject()));
  }
}

get()
Function call

  void initState() {
    imagesHandler = get();
...

Error stack:

I/flutter ( 5326): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 5326): │ #0   new InjectorIO.start (package:injectorio/src/io.dart:44:14)
I/flutter ( 5326): │ #1   MyApp.build (package:bridi/main.dart:48:16)
I/flutter ( 5326): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 5326): │ 🐛 Initiated InjectorIO in mode: InjectorMode.DEBUG
I/flutter ( 5326): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 5326): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 5326): │ #0   DefinitionRegistry._log (package:injectorio/src/bean_registry.dart:83:44)
I/flutter ( 5326): │ #1   DefinitionRegistry._showCreateSingle (package:injectorio/src/bean_registry.dart:86:34)
I/flutter ( 5326): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 5326): │ 🐛 InjectorIO:::	+++ Register single	JobsController
I/flutter ( 5326): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 5326): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 5326): │ #0   InjectorIO._register (package:injectorio/src/io.dart:52:14)
I/flutter ( 5326): │ #1   InjectorIO.module.() (package:injectorio/src/io.dart:67:42)
I/flutter ( 5326): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 5326): │ 🐛 Registered definition : Instance of 'Definition'
I/flutter ( 5326): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 5326): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 5326): │ #0   InjectorIO.module (package:injectorio/src/io.dart:69:14)
I/flutter ( 5326): │ #1   MyApp.build (package:bridi/main.dart:48:24)
I/flutter ( 5326): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 5326): │ 🐛 Succesfully registered module : Instance of 'Dependencies'
I/flutter ( 5326): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[Easy Localization] Load Localization Delegate
I/flutter ( 5326): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 5326): │ #0   DefinitionRegistry._log (package:injectorio/src/bean_registry.dart:83:44)
I/flutter ( 5326): │ #1   DefinitionRegistry._showInstanceNotFound (package:injectorio/src/bean_registry.dart:91:7)
I/flutter ( 5326): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 5326): │ 🐛 InjectorIO:::	!!!--- Instance of type ImagesHandler not found ---!!!
I/flutter ( 5326): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following _Exception was thrown building Builder:
Exception: Instance of ImagesHandler not found. Make sure you added
        it by using module or with [single()], [factory()] definition.

The relevant error-causing widget was: 
  CupertinoTabView file:///home/ark/Haizen/projetox/novaPasta/bridi-mobile/lib/main.dart:199:22
When the exception was thrown, this was the stack: 
#0      DefinitionRegistry.get (package:injectorio/src/bean_registry.dart:60:7)
#1      get (package:injectorio/src/component_binder.dart:22:24)
#2      get (package:injectorio/injectorio.dart:9:15)
#3      _CustomerEditProfileScreenState.initState (package:bridi/views/customer/customer_profile_editing_screen.dart:109:21)
#4      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4640:58)

```

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