injectable
injectable copied to clipboard
Unique named injection cannot be defined depending of the environment.
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
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
Fixed in the latest version - 2.3.2. Not tested on 2.3.1.
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.... :/
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