2

我想在后面的代码中创建摘要,因为我的所有路由当前都在 AppConfig 类中配置,但据我所知,只能使用 Route 属性包含摘要。

前任:

[Route("/myrequest/{Id}, "GET", Summary="My Summary", Notes="My Notes")]
public class MyRequest : IReturn<MyResponse>
{
    public int Id { get; set; }
}

但我的路线配置如下:

base.Routes
    .Add<MyRequest>("/myrequest", "GET");

基本上我想做类似的事情:

base.Routes
    .Add<MyRequest>("/myrequest", "GET", "My Summary", "My Notes");

目前有没有办法做到这一点?

编辑:

我正在使用 ServiceStack 版本 3.9.71

4

1 回答 1

3

所以我又看了一下添加路由,发现实际上有一个重载允许您指定摘要和注释。

这是如何做到的:

base.Routes
    .Add(typeof(MyRequest), "/myrequest", "GET", "My Summary", "My Notes");

我真的希望 ServiceStack 会为 Generic Add 方法添加一个重载,这样我就不必以这种方式指定类型。

编辑:

我决定编写一个扩展方法来获得我最初寻找的方法。

public static class RouteExtensions
{
    public static ServiceStack.ServiceHost.IServiceRoutes Add<T>(
        this ServiceStack.ServiceHost.IServiceRoutes route, 
        string restPath,
        string verbs,
        string summary,
        string notes)
    {
        route.Add(typeof(T), restPath, verbs, summary, notes);

        return route;
    }
}

现在我可以这样做了:

base.Routes
    .Add<MyRequest>("/myrequest", "GET", "My Summary", "My Notes");
于 2014-02-07T20:23:20.730 回答