gbtb16 / kiwi

A simple compile-time dependency injection library for Dart and Flutter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[kiwi_generator] Registering singleton in module with dependencies from another module

hazzo opened this issue · comments

It's possible to register a singleton in a file that has a dependency a singleton of another file?
Ex.:

// ModuleA.dart
abstract class ModuleA {
    @Register.signleton(SingletonA)
     void configure();
}

// SingletonA.dart
class SingletonA {
    SingletonA(SingletonB singletonB)
}
// ModuleB.dart
abstract class ModuleB {
    @Register.signleton(SingletonB)
     void configure();
}

// SingletonB.dart
class SingletonB {
    SingletonB()
}

I tried it and the generated file wont have the imports of the missing clases that are not imported in the file of ModuleA.
I have to go to the generated file and import those missing dependencies. Don't know if is possible to reference another files inside the generated file.

Thanks!

You need to manually import the the singletonB import in your ModuleA.dart because the generators will store the dependencies in the same KiwiContainer it will resolve the dependency correctly.

It is not possible to generate the import itself because we can't add imports to a .g.dart file that is the reason you need to add the import yourself in the modulea.dart file

Okay 👌. I supposed there was a reason. Thanks again and congrats for the package, the generator is a life saver!!

I want to pass the credits to @letsar. I took over the package. Did some refactors, and made it Flutter friendly :)
I am happy you are enjoying 🥝

So kudos to @letsar too :)