Skip to content

Defaults.WithoutCodec to avoid binding collisions. - #67

Merged
codefromthecrypt merged 1 commit into
masterfrom
defaults-withoutcodec
Sep 15, 2013
Merged

codefromthecrypt merged 1 commit into
masterfrom
defaults-withoutcodec

Conversation

@codefromthecrypt

Copy link
Copy Markdown

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.

    @dagger.Module(includes = { ReflectiveFeign.Module.class, Defaults.WithoutCodec.class, GsonModule.class, ... })
    public static final class FeignModule {

codefromthecrypt pushed a commit that referenced this pull request Sep 15, 2013
Defaults.WithoutCodec to avoid binding collisions.
@codefromthecrypt
codefromthecrypt merged commit 0d947b8 into master Sep 15, 2013
@codefromthecrypt
codefromthecrypt deleted the defaults-withoutcodec branch September 15, 2013 09:58
@codefromthecrypt codefromthecrypt mentioned this pull request Sep 15, 2013
5 tasks done
@cloudbees-pull-request-builder

Copy link
Copy Markdown

feign-pull-requests #87 SUCCESS
This pull request looks good

@davidmc24

Copy link
Copy Markdown
Contributor

@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.

@codefromthecrypt

Copy link
Copy Markdown
Author

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 Defaults

wdyt?

@codefromthecrypt

Copy link
Copy Markdown
Author

I think if we took the default encoder/decoder out of Defaults, then it could make more sense to make GsonModule addsTo=Defaults.class Reason is that it is adding to Defaults and making it whole. just a thought..

@codefromthecrypt

Copy link
Copy Markdown
Author

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.

@davidmc24

Copy link
Copy Markdown
Contributor

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.

@codefromthecrypt

Copy link
Copy Markdown
Author

thx @davidmc24 I put this into issue #68

velo pushed a commit that referenced this pull request Oct 8, 2024
Defaults.WithoutCodec to avoid binding collisions.
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 this pull request may close these issues.

3 participants