-
Notifications
You must be signed in to change notification settings - Fork 343
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
Add ControllerFactory. #513
base: develop
Are you sure you want to change the base?
Add ControllerFactory. #513
Conversation
conductor/src/main/java/com/bluelinelabs/conductor/Controller.java
Outdated
Show resolved
Hide resolved
conductor/src/main/java/com/bluelinelabs/conductor/Controller.java
Outdated
Show resolved
Hide resolved
I would make the Factory an interface and make the default factory final and hide the implementation. Then you could also just do a identity check in if(FACTORY != DefaultControllerFactory.instance() {
return
} Another approach (which I prefere) would be to pass the factory to conductor upon initialzation: Then in But I really like the idea to get rid of reflection and allow constructor injection. |
8783a95
to
6d415cf
Compare
Thanks for the feedback! I've made the interface change. If Dagger doesn't need first-party support for assisted injection, it can be provided through something like AssistedInject or AutoFactory. |
conductor/src/main/java/com/bluelinelabs/conductor/ControllerFactory.java
Show resolved
Hide resolved
6d415cf
to
2fd7b55
Compare
ControllerFactory allows Controllers to be provided dependencies through their constructors after a configuration change. This means field injection is no longer a requirement when injecting dependencies into a Controller.
2fd7b55
to
bc4bb1c
Compare
@@ -92,30 +92,34 @@ | |||
private boolean isPerformingExitTransition; | |||
private boolean isContextAvailable; | |||
|
|||
static volatile ControllerFactory FACTORY = DefaultControllerFactory.INSTANCE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Controller shouldn't know about any factory
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
final class DefaultControllerFactory implements ControllerFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think DefaultControllerFactory should implement default logic for creating Controller, but not just be a stub in logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could only do that without extra reflection if the first argument for create
was a Class
.
@PaulWoitaschek I had a look into adding Assuming we store the ControllerFactory in the LifecycleHandler, we would need some way for a |
@EricKuck I'm keen to hear your thoughts on this and move this forward |
One more thing: if Factory instantiates Controllers, we need a way to create transaction without instantiating controllers ourselves. |
|
ControllerFactory allows Controllers to be provided dependencies through their constructors after a configuration change. This means field injection is no longer a requirement when injecting dependencies into a Controller.
Usage
Currently, you have a single
ControllerFactory
for your entire app. Having a ControllerFactory perActivity/ViewGroup
would be better but I don't know enough about Conductors internals to make that change.Closes #510.