4

According to Mythz (Getting ServiceStack to retain type information) he recommends not using inheritance in DTOs. What about the use case where I want every request to optionally provide an API key, or a location parameter? Are interfaces bad to use but abstract classes are ok? Anyone have any recommendation?

Community
  • 1
  • 1
mariocatch
  • 8,305
  • 8
  • 50
  • 71

2 Answers2

3

Your use case, "every request to optionally provide an API key, or a location parameter" is traditionally handled in SS through filter attributes

Here's an example where a required authorization header is managed both server-side and client-side.

Given the right requirements, Mythz has recommended the use of a custom interface in DTOs: "Request DTO that implements a custom ITenant interface that just has a Tenant property. Another solution is to use a IHttpRequest.Tennant() extension method that you can re-use inside all services which inspects the AbsoluteUri or RawUrl properties." See this comment: (Multi-tenant ServiceStack API, same deployment to respond to requests on different hostnames?)

Community
  • 1
  • 1
Pauli Price
  • 4,187
  • 3
  • 34
  • 62
2

I use interfaces and then check for implementations of the interface in a request filter.

jeffgabhart
  • 1,117
  • 7
  • 13