8000 Explicit interface inheritance by Sergio0694 · Pull Request #633 · reactiveui/refit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Explicit interface inheritance #633

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

Merged
merged 15 commits into from
Mar 12, 2019
Merged

Explicit interface inheritance #633

merged 15 commits into from
Mar 12, 2019

Conversation

Sergio0694
Copy link
Contributor
@Sergio0694 Sergio0694 commented Mar 7, 2019

This continues the work from @Iss0 in #523 on the interface inheritance for Refit services.
In particular, here I've updated the stub generator as @onovotny asked, so that Refit now does explicit interface inheritance in order to properly handle cases where multiple interfaces declare methods with the same name but different return values.

@clairernovotny
Copy link
Member

Looks good - one question came up as I was looking at the code: what happens if there are different, possibly conflicting attributes on the interface -- for Header, Auth, or any of the others. Which one wins and is it clear?

@Sergio0694
Copy link
Contributor Author
Sergio0694 commented Mar 7, 2019

@onovotny I'm not sure how refit currently handles these cases, but I'd say the result here depends on the current behavior of the library, that is:
• If it throws when more than a single attribute of that kind is present, it'll do the same here
• If it just picks the first one if finds, it'll use the first one depending on how runtime sorts the attributes across the inherited interfaces (I'd assume that depends on the actual order you use when declaring them?)

If the first case is true (it should be) then it should be fine, otherwise if you'd like refit to throw when more than one attribute of that kind is present, I guess that's something that isn't strickly related to this PR in particular, and should be fixed for the library as a whole (maybe with a dedicated PR?).

8000 EDIT: double checked, the current behavior seems to be the expected one. With this code:

[Headers("User-Agent: AAA")]
public interface IAmInterfaceA
{
    [Get("/get?result=Ping")]
    Task<string> Ping();
}

[Headers("User-Agent: BBB")]
public interface IAmInterfaceB
{
    [Get("/get?result=Pong")]
    Task<string> Pong();
}

[Headers("User-Agent: CCC")]
public interface IAmInterfaceC : IAmInterfaceB, IAmInterfaceA
{
    [Get("/get?result=Pang")]
    [Headers("User-Agent: PANG")]
    Task<string> Pang();

    [Get("/get?result=Foo")]
    Task<string> Foo();
}

Calling Pang() uses "PANG" as user agent, while Foo() uses "CCC", which is indeed the inner-most attribute value. This should be the correct behavior, right?

@Sergio0694
Copy link
Contributor Author

Hey @onovotny - not sure if you saw my updated reply (I've edited my comment with more info after I first replied to you), the attributes handling seems to be working fine and as expected (see my code snippet above).

Please let me know if there's anything else you need or if this PR is good to go for you, I'm looking forward for finally being able to use this in my project 😄
Thanks again for your time!

@clairernovotny
Copy link
Member

As this is new behavior (Refit didn't have any inheritance before), that seems okay. Please update the main docs (the readme) showing this new behavior and explaining what happens if there's multiple conflicting attributes and then this can be merged.

@clairernovotny clairernovotny merged commit a124fb5 into reactiveui:master Mar 12, 2019
@lock lock bot locked and limited conversation to collaborators Jun 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0