bluelinelabs / Conductor

A small, yet full-featured framework that allows building View-based Android applications
Apache License 2.0
3.89k stars 342 forks source link

Controller Constructor Injection #510

Open AngusMorton opened 5 years ago

AngusMorton commented 5 years ago

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?

timrijckaert commented 5 years ago

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 commented 5 years ago

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

sgrekov commented 5 years ago

@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 commented 3 years ago

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