Skip to content
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

Stubs aren't generated unless service is instantiated in the same project #65

Closed
bennor opened this issue Oct 23, 2014 · 3 comments · Fixed by #67
Closed

Stubs aren't generated unless service is instantiated in the same project #65

bennor opened this issue Oct 23, 2014 · 3 comments · Fixed by #67
Labels

Comments

@bennor
Copy link
Contributor

bennor commented Oct 23, 2014

InterfaceStubGenerator needs there to be a call to RestService.For<ISomeApi>() in the same project that ISomeApi is defined or it won't generate a stub for it.

We should be able to fix this by looking for all interfaces that have an attribute derived from HttpMethodAttribute on a method and making stubs for them.

This awesome error shows up when you try to create the service later too: https://gist.github.com/screamish/ccc46cb849cc4497ea8e

@Suchiman
Copy link

For me this also happened by just putting the ISomeApi into another file in the same project than the file which does RestService.For.

So i had a ISomeApi.cs containing the ISomeApi Interface but calling RestService.For<ISomeApi>() from Client.cs in the same Project did result in an empty RefitStubs.cs (besides the PreserveAttribute) with the same error as described.

To workaround that i put a

public static class SomeApi
{
    public static ISomeApi GetService(string address)
    {
        return RestService.For<ISomeApi>(address);
    }
}

in the same file which works but is not that nice.

@carl-berg
Copy link
Contributor

👍 for this one. In my current project we are using a factory that wraps the calls for RestService.For (and adds logging and other interesting things) which makes the current implementation fall flat for us (when upgrading from Refit 1.3 to 2.0.2). As a side note calling Refit.RestService.For (because of a namespace clash) does not seem to generate any stubs.

@bennor
Copy link
Contributor Author

bennor commented Oct 27, 2014

This will be fixed by #67, which should be merged when @paulcbetts has had time to review it. 😸

If you are desperate, you could build your own InterfaceStubGenerator.exe from that PR, but ⚠️ it may still have some changes coming before it's nugetted.

In the meantime, a temporary workaround is just to have another class in the same project as the interfaces that calls RestService.For<IYourInterface>() for all of the interfaces.

image

@lock lock bot added the outdated label Jun 25, 2019
@lock lock bot locked and limited conversation to collaborators Jun 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants