Skip to content

How to registerFactory but with dependencies? #104

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

Closed
ydhnwb opened this issue Aug 27, 2020 · 2 comments
Closed

How to registerFactory but with dependencies? #104

ydhnwb opened this issue Aug 27, 2020 · 2 comments

Comments

@ydhnwb
Copy link

ydhnwb commented Aug 27, 2020

How to registerFactory but with dependencies?
For example in Kotlin Koin will be like

val networkModule = modules {
     single { RetrofitInstance() }
}

val repoModule = modules {
   //userRepo depends on RetrofitInstance
   factory { UserRepository(get()) }
}

How to achieve this in get_it?
I created the setup like this

GetIt locator = GetIt.instance;

void setupGetIt() {
  locator.registerSingleton(AppDatabase());

  //then how to register UserRepository with dependencies?


}

There is only registerSingletonWithDependencies available, registerFactoryWithDependencies is not exists.
Or maybe there is another approach to achieve this?

@escamoteur
Copy link
Collaborator

IMHO dependencies don't really make sense for a factory. If you need to be sure that another registered object is available use allReady or isReady to wait for it.

@ydhnwb
Copy link
Author

ydhnwb commented Aug 27, 2020

Okay, I will try it

@ydhnwb ydhnwb closed this as completed Aug 28, 2020
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