Repository navigation
Defaults.WithoutCodec to avoid binding collisions. - #67
Conversation
Defaults.WithoutCodec to avoid binding collisions.
|
feign-pull-requests #87 SUCCESS |
|
@adriancole Interesting approach. I'm still pretty new to Dagger (not having used it other than with Feign), so there may be nuances that I'm not aware of yet. I assume what was going on here was that in Denominator, you were creating a feign instance using the pure-dagger method, and got a dagger multiple-bindings error when using the GsonModule, as there were then two encoders and two decoders (default + gson). Would an alternate approach to bypassing that error be to add ", overrides=true, addsTo=Feign.Defaults.class" to the Module annotation in GsonModule? This approach looks to also solve the problem, and may well be more flexible, but I'm interested in understanding the differences. |
|
We could change gson to be rebased on top of Defaults. However, this confuses intent of the tree a bit, as gson is otherwise self-enclosed (i.e. it doesn't need anything else in Defaults, nor would most Codec modules). WRT pure Dagger, I don't think there would be any case where someone would be using dagger and also desire the default decoders. When folks aren't using Dagger, they'd be using the builder.. maybe we should just move these there? That would allow us to kill Defaults.WithoutCodec and retain the cleanest behavior. ex. // change this:
@Inject Encoder encoder;
@Inject Decoder decoder;
// to
Encoder encoder = new Encoder.Default();
Decoder decoder = new Decoder.Default();
// then delete Defaults.Codec
// then collapse Defaults.WithoutCodec into Defaultswdyt? |
|
I think if we took the default encoder/decoder out of Defaults, then it could make more sense to make GsonModule |
|
p.p.s. I think we still have a good bit of analysis on the best dagger config to use, and dagger will change more, too. It is a bit of a journey. One thing I try (in vain) to avoid, is using the overrides flag, which is documented as "a dangerous feature". It is actually kind of tough to do both defaults and also avoid use of overrides! The dagger opinion on this issue is to try to optimize for convenience balanced with lack of "use all Module attributes" :) In this case, for example, Client or Retryer are pretty good to keep in Defaults, but there's a question on the encoder/decoder stuff. |
|
I think you're right that basically every dagger-based user ever is going to want to specify specify at least one non-default decoder/encoder. It's possible they might want either the default encoder or decoder, but likely not both. They'll either be using an off-the-shelf module that provides both, or defining their own module that defines what they want (which can use the default encoder/decoder if they so wish). This would be a bit of a behavior change for dagger-based users; previously, if they had signatures that used only Strings, I believe it would "just work" without any encoder/decoder provided. I think it's an acceptable breaking change however, given the much more significant changes we've already made. So... I'm +1 with having Feign.Defaults not include an encoder/decoder, and having Feign.Builder provide default encoder/decoder if not overridden by the user. |
|
thx @davidmc24 I put this into issue #68 |
Defaults.WithoutCodec to avoid binding collisions.
When constructing pure Dagger apps, it is hard to compose a tree that includes Defaults and GsonModule. This is because there's a clash in Encoder/Decoder that is particularly hard to work around. This introduces Defaults.WithoutCodec, which avoids this collision for the common case of pure-dagger use as exists in Denominator.
ex.