Closed mawt closed 9 years ago
Hello,
Just to point out that in the new version of WebApiProxy.CSharp the generation of the proxy is not coupled anymore by default to the compile task http://www.faniereynders.com/2015/01/an-update-on-webapiproxy.html?m=1
Regards, William Obando
Hi @mawt, yes @wocar is correct. In the new version you will be able to generate the proxy on demand using a Powershell commandlet.
@mawt the generation of interfaces might be included in a future version, but in the meanwhile here is a great workaround that does exactly what you want:
Let's say you have a PeopleClient
that got generated by WebApiProxy. The generated proxy clients are partial classes so assuming the client is generated in the WebApi.Proxies.Clients
namespace, you can create a seperate partial class with the same namespace and save it as PeopleClient.partial.cs
for instance.
namespace WebApi.Proxies.Clients
{
public partial class PeopleClient
{
}
}
Now using Visual Studio's refactoring tools you can extract an interface from the PeopleClient
class by right-clicking on the class name, point to Refactor and select Extract Interface. (You can also do this by pressing CTRL
+R
, CTRL
+I
)
This will create an interface from the PeopleClient
and automatically implement it on the partial class you've created.
Hope this helps.
For completeness I added interfaces and an exception type.
https://github.com/mawt/WebApiProxy/commit/59fe0c6ae656121aa6f10392d5758dab869d7049
Thank you @mawt, I'll merge after a quick review. Kudos!
This feature is added to the current release and is part of #39 and closes #33
You might want to check the nuspecs - a complete merge of this the above branch prefixes the project name and bumps the version number I use in a local repo
Hi @mawt,
I noticed that and fixed in in https://github.com/faniereynders/WebApiProxy/commit/2fb60bc193e626305d4d8823aa873e6032ab2111. Everything should work fine.
Hi
Thanks for all the hard work!
One of the limitations I came across and fixed on my local branch was the lack of partial interfaces for dependency injection.
I've added the generator in a common project, subclass the generated services (to provide a custom HttpClientHandler for basic auth) and inject.
Another problem I've stumbled across is the tight coupling between the task and visual studio, making the compile/package reinstall thing a bit of a pain as it requires a restart. If I get time I might start a fork that turns the code generator into an external executable and use MustacheSharp for templating. Any thoughts?
Kind regards
Matt