0

I have versioned DTOs (for better or worse) like this:

[Route("/v1/login", Verbs = "POST")]
[Route("/v2/login", Verbs = "POST")]        
[DataContract]
public class Login : IReturn<LoginResponse>
{
    [DataMember( IsRequired = true)]
    public string Username { get; set; }

    [DataMember( IsRequired = true)]
    public string Password { get; set; }

    [DataMember( IsRequired = false)]
    public string Key{ get; set; }//added for v2
}

My issue is that when consuming the api via .net client, I cant seem to figure out how to specify which version of the route to use (other than modifying the base url when initializing the jsonclient, which does not work in all our use cases). Its as though the DTO defaults to 1 route, even when there are more route options available.

Other than manually specifying the "v2" route during the post, is there a better way to accomplish this default route behavior?

jglassco
  • 133
  • 11

1 Answers1

0

The routes are ambiguous and can't be inferred so you'll need to pass it in at the call-site, e.g:

var response = client.Post<LoginResponse>("/v2/login", new Login { .. })

Message-based designs lend themselves to designing and backwards and forwards compatible DTO's which don't require versioning, but if you must version check out ServiceStack's recommended versioning strategy.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Forcing a client to specify the route manually in every call above V1 seems like a wasted opportunity, especially when all the associate routing information is bound to that DTO (just missing version info). If I get the time I will try to build a method of extracting the correct route from a DTO based on a specified version and post an example here. I understand that versioning is all relative, so it may not make sense to build this into the SS client framework - but it seems to make sense for (at least some) of our implementations. Thanks for the answer! – jglassco Jul 03 '15 at 19:09
  • @jglassco right, but this isn't the recommended versioning strategy, [this is](http://stackoverflow.com/a/12413091/85785) which doesn't require explicit support since the version is naturally populated in the Constructor. Add ServiceStack Reference also supports adding an [implicit Version number in Generated DTO's](https://github.com/ServiceStack/ServiceStack/wiki/CSharp-Add-ServiceStack-Reference#addimplicitversion). – mythz Jul 03 '15 at 21:25