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

Automatic scan for Modules in dependencies #174

Open
tprochazka opened this issue Sep 27, 2024 · 2 comments
Open

Automatic scan for Modules in dependencies #174

tprochazka opened this issue Sep 27, 2024 · 2 comments

Comments

@tprochazka
Copy link

I'm migrating from Hilt and it has one great feature that is missing in Koin.

Inside the library, you can create a module that will be part of the default singleton component.

@Module
@InstallIn(SingletonComponent.class)
public final class MyLibraryModule {

When you add that library to the project, that library will automatically and without any setup provide implementations for all objects defined in that module.

In Koin you need to add a module to the Koin setup closure manually.
Would be great to have as part of the Koin Annotation project the possibility to do something similar, scan for all modules in all libraries used in the project and somehow marked as public (shared). Libraries still can have their own internal modules.

To explain motivation for that.
We have many libraries in the company and setting up them is quite complex and tedious work.
I would like to make it plug and play. For example, one library will provide OkHttpClient and all other libraries can just use it by injection, without necessary to call something like init(okHttpClient) for every library. Or when some library needs configuration, it can just expose the interface and use the injection, and the app using that library will be responsible to provide the implementation. If you do not provide it, it will crash during compile time and you will immediately know that you miss something. Or tracking, one library can provide just a general interface for tracking and all other libraries will use just this interface. In the app I will just add a dependency with tracking implementation, like Firebase, and done, it will immediately start tracking. Or I can simply decide that I will do my own tracking directly in the app, so I will just provide my own implementation of that tracking interface in the app.

Hilt/Dagger automatically generates a special package in the library with all the information about what provides and needs.
And during the compilation, KSP checks everything in that one package on the classpath, so it will very fastly get information from all libraries.

But there will be an issue that Koin does not have @Inject annotation so it doesn't know during the compile name all od the requested dependencies that need to be fulfilled, right?

@arnaudgiuliani
Copy link
Member

Hello, interesting feedback. In your case, you don't use directly MyLibraryModule but it's installed in the singleton components, right?

@tprochazka
Copy link
Author

Do you mean in hilt? Yes. It is in the example in the first post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants