简体   繁体   English

在ServiceStack中命名服务方法

[英]Naming service methods in ServiceStack

I am creating my first ServiceStack application. 我正在创建我的第一个ServiceStack应用程序。 I think it is great but find that I have limited flexibility in the naming of methods in the Services. 我认为这很好,但是发现在服务中方法的命名方面我的灵活性有限。 An example of this is I wanted to name this method GetChannels(AllChannels) but the route was not created as seen in the metadata page. 一个示例是我想将此方法命名为GetChannels(AllChannels),但未创建该路由,如元数据页面中所示。 I found it did work if I named it 我发现它确实有效,如果我将其命名

        public object Get(AllChannels request)

Do these methods have to be named by the Verb that will call it? 这些方法是否必须由将要调用它的动词命名? I am doing my routing in AppHost in the Configure(). 我正在通过Configure()在AppHost中进行路由。

Am I missing something? 我想念什么吗? Is there a way for the route to specify the method to call? 路由是否有办法指定要调用的方法?

You must use either the Verb that you want to limit your Service to be called from or Any() which allows it to be called from ANY HTTP verb. 您必须使用要限制要从中调用服务的动词,或者必须使用允许从ANY HTTP动词调用它的Any() Your Operation name in ServiceStack should instead be on the Request DTO, so I would change your Request DTO to be: 相反,您在ServiceStack中的操作名称应在Request DTO上,因此我将您的Request DTO更改为:

public object Get(GetAllChannels request)

ServiceStack promotes a message-based design where your Request DTO defines your Service contract not your methods. ServiceStack促进了基于消息的设计,其中您的请求DTO定义您的服务合同而不是您的方法。 Please read these existing answers for learning how to design message-based Services with ServiceStack: 请阅读以下现有答案,以了解如何使用ServiceStack设计基于消息的服务:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM