-
Notifications
You must be signed in to change notification settings - Fork 1
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 support for assisted inject #59
Conversation
d42419b
to
7fab84b
Compare
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.
Regarding release see inline comments :).
I don't have too much at the moment in terms of the actual solution itself, however I'd like to understand better why we need a breaking change in the return of InjectionPointExtractor
? I get one is currently introduced in this solution, but I don't understand why.
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.
LGTM 👍
@jsfr From my understanding, we have to return the
The factory here is used to new up multiple different classes which are all using assisted inject, and hence each separate class has its own
So the relationship between We then have to follow up by matching the return type in the original visitor, even though the logic here has not changed. |
@jsfr Thanks for your feedback! I apologize I wasn't clearer in my original description. I have updated the PR description with a more in-depth overview of how/why I made the proposed changes. |
@jsfr I have made the requested changes to follow |
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.
Thank you for the context @ryuichi7, and agreed on the addition to the README.
This adds support for using the guice extension
assistedInject
.Without this change, we can't use
Prop
instances in classes usingassistedInject
. The current visitor implementation does not scan the factory function assistedInject methods forinjectionPoints
.This PR add support to create an
injectionPoint
for each factory method so that they can be properly scanned and have dynamic props injected.Why do we need this change?
The current architecture of this lib is composed of a
PropMappingVisitor
which is an implementation of ElementVisitor. This visitor iterates over all the Elements of a module and for each element invokes a target visitor calledInjectionPointExtractor
which implements BindingTargetVisitor.The goal of the
InjectionPointExtractor
is to extract theInjectionPoint
of a given binding, so that the arguments can be inspected by thePropMappingVisitor
and any named props are then explicitly bound.Each override of the
visit
function in theBindingTargetVisitor
is an implementation ofBinding
that returns a single injection point. i.e. (LinkedKeyBinding
,ProviderKeyBinding
,ProvidesMethodBinding
,UntargettedBinding
). They return injectors that will "new" up one implementation type.This is not the case, however, with the
AssistedInjectBinding
. UsingAssistedInject
and, specifically, the FactoryModuleBuilder employs the factory pattern. Meaning that a given factory could potentially return multiple implementations for a class and multiple injection points.For instance, a factory might look like this:
Where each factory function possesses its own implementation type.
The
AssistedInjectBinding
binding has an attribute calledgetAssistedMethods
which returns a list of AssistedMethod instances from where we can extract theInjectionPoint
for each method.This, however, results in possibly multiple
InjectionPoint
s being returned, which breaks the current return type of thevisit
function implementations forInjectionPointExtractor
.My goal was to introduce the least amount of change, which is why I decided to simply change the return type of the
InjectionPointExtractor
to allow forBinding
implementations that may return multipleInjectionPoint
s.I considered possibly creating a
MultipleInjectionPointExtractor
, but then I would need to inspect theElement
type in thevisit
function of thePropMappingVisitor
to decide which target visitor to invoke the binding with.Note
This is a breaking change. In order to make things work as expected, we need to return an
Iterable<InjectionPoint>
fromInjectionPointExtractor