injectable icon indicating copy to clipboard operation
injectable copied to clipboard

Unique named injection cannot be defined depending of the environment.

Open sbatezat opened this issue 10 months ago • 4 comments

I've got this :

  @Named("test")
  @LazySingleton(env: ["development"])
  List<Interceptor> provideDevelopmentInterceptors(
    @Named(NamedInjections.sharedInterceptors) List<Interceptor> shared,
    MockInterceptor mockInterceptor,
  ) {
    return [
      ...shared,
      mockInterceptor,
    ];
  }

  @Named("test")
  @LazySingleton(env: ["production"])
  List<Interceptor> providerProductionInterceptors(
    @Named(NamedInjections.sharedInterceptors) List<Interceptor> shared,
  ) {
    return [
      ...shared,
    ];
  }

On development, there is never an available List<Interceptors> named "test". I've got this error message :

Bad state: GetIt: Object/factory with with name test and type List<Interceptor> is not registered inside GetIt. (Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance; Did you forget to register it?)

If I switch declaration order between development and production, everything works fine... on development. To summarize, a unique named injection (here : "test") cannot be defined depending of the environment, only the last declaration survives.

Dependencies used :

  get_it: ^7.6.2
  injectable: ^2.3.0

Dev dependencies used :

  build_runner: ^2.4.6
  injectable_generator: ^2.4.0

sbatezat avatar Sep 02 '23 13:09 sbatezat

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

github-actions[bot] avatar Oct 06 '23 08:10 github-actions[bot]

Fixed in the latest version - 2.3.2. Not tested on 2.3.1.

sbatezat avatar Oct 10 '23 14:10 sbatezat

I forgot that issue, but it's still there. I've workaround this with an ugly if depending of the environment. I was thinking it was resolved because it seems to be a random behavior. Sometimes dependency is resolved, sometimes not, depending of dependencies there is to instanciate.

Very weird behavior, difficult tu reproduce with a sample.... :/

sbatezat avatar Feb 28 '24 12:02 sbatezat

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

github-actions[bot] avatar Mar 30 '24 08:03 github-actions[bot]