【问题标题】:ServiceStack DTO with inheritance具有继承的 ServiceStack DTO
【发布时间】:2013-09-07 03:41:03
【问题描述】:

根据 Mythz (Getting ServiceStack to retain type information),他建议不要在 DTO 中使用继承。我希望每个请求都可选地提供 API 密钥或位置参数的用例怎么样?接口不好用但抽象类可以吗?有人推荐吗?

【问题讨论】:

    标签: servicestack


    【解决方案1】:

    您的用例“每个可选地提供 API 密钥或位置参数的请求”传统上在 SS 中通过 filter attributes 处理

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

    鉴于正确的要求,Mythz 建议在 DTO 中使用自定义接口:“请求 DTO 实现仅具有租户属性的自定义 ITenant 接口。另一种解决方案是使用 IHttpRequest.Tennant() 扩展方法您可以在检查 AbsoluteUri 或 RawUrl 属性的所有服务中重复使用。”看到这条评论:(Multi-tenant ServiceStack API, same deployment to respond to requests on different hostnames?)

    【讨论】:

    • 如果我只是向我的 DTO 添加另一个接口(除了 IReturn)会有多糟糕? “坏”是指它会损害序列化的效率吗?
    • 我不能说。我认为这只是你必须测试的东西。
    【解决方案2】:

    我使用接口,然后在请求过滤器中检查接口的实现。

    【讨论】:

      猜你喜欢
      • 2015-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-20
      相关资源
      最近更新 更多