ServiceStack DTO with inheritance

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

+4
source share
2 answers

In your use case, "each request does not necessarily provide an API key or location parameter" is traditionally processed in SS through filter attributes

Here is an example where the required authorization header is managed both on the server side and on the client side.

Given the correct requirements, Mythz recommended using the user interface in the DTO: "Request a DTO that implements the ITenant user interface that has the Tenant property. Another solution is to use the IHttpRequest.Tennant () extension method, which you can reuse inside all the services that check AbsoluteUri or RawUrl properties. " See this comment: ( Multi-tenant ServiceStack API, same deployment to respond to requests for different host names? )

+3
source

I use interfaces and then check the implementation of the interface in the query filter.

+1
source

Source: https://habr.com/ru/post/1501036/


All Articles