0

in an application I've got a request that inherits from a base class, I've got a strange problem when I look at the metadata I only get "Max" serialized and not also "Header"

When executing the application it works...it seems to be something wrong when preparing the request stub

public class SomeRequest : SomeBaseClass<int>
{
    public int Max { get; set; }
}

public class SomeBaseClass<T> 
{
   public Header SomeHeader { get; set; }

   public T Response {get;set;}
}


public class Header
{
    public int IDUser { get; set; }

    public string Name { get; set; }
}    

Can anyone help me on this?

P.S. I'm aware the hinerithance inheritance is not good in SS but I've got almost all requests that needs the same header parameter

Thanks

advapi
  • 3,661
  • 4
  • 38
  • 73

1 Answers1

3

You have kind of already answered your own question. SS recommends against inheritance, as a result the metadata doesn't support describing your DTO. This is by design. I would follow the recommended design pattern.

Create your objects in full. It is a little more effort, but you will get the right meta data, your service DTO is clear to clients and follows ServiceStack's DRY principle.

public class SomeRequest
{
    public int Max { get; set; }
    public Header SomeHeader { get; set; }
    public int Response { get; set; }
}

Quoting mythz (ServiceStack creator) on another DTO inheritance question:

Inheritance in DTOs is a bad idea - DTO's should be as self-describing as possible and by using inheritance clients effectively have no idea what the service ultimately returns. Which is why your DTO classes will fail to de/serialize properly in most 'standards-based' serializers.

The alternative would be to implement your own MetaDataFeature. But that's not an easy task, and so I guess the effort to implement this outweighs writing the full DTO without inheritance.

Community
  • 1
  • 1
Scott
  • 21,211
  • 8
  • 65
  • 72