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

Controller Constructor Injection #510

Open
AngusMorton opened this issue Jan 14, 2019 · 4 comments · May be fixed by #513
Open

Controller Constructor Injection #510

AngusMorton opened this issue Jan 14, 2019 · 4 comments · May be fixed by #513

Comments

@AngusMorton
Copy link

Currently, when injecting dependencies into a Controller, we can't perform constructor injection because Conductor needs to be able to recreate the Controllers after a configuration change. This sucks because field injection is confusing and error-prone.

Can we provide an abstraction like a ControllerFactory which would behave similarly to androidx.work.WorkerFactory in that consumers could override it with their own ControllerFactory?

@AngusMorton AngusMorton linked a pull request Jan 16, 2019 that will close this issue
@timrijckaert
Copy link

Really good idea.
However if you are looking for a Dagger solution to this I have made this proof of concept which will let you inject members of Controllers.
Also there is this library AssistedInject which will let you inject dependencies using the constructor.

@hijamoya
Copy link

You can see my example for dagger.
https://github.com/hijamoya/Android-Kotlin-Dagger2-Conductor-Example

@sgrekov
Copy link

sgrekov commented Sep 1, 2019

@hijamoya Thanks for the sample. But in your sample I don't see constructor injection in controllers. They are still injecting to the member fields.

@Miha-x64
Copy link

Miha-x64 commented Oct 8, 2020

For reference, here's an example of constructor injection with Fragments before FragmentFactory was introduced: https://github.com/Miha-x64/Flawless/

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

Successfully merging a pull request may close this issue.

5 participants