1
我使用下面的行試圖自動註冊航線ServiceStack wiki頁面上指定https://github.com/ServiceStack/ServiceStack/wiki/RoutingServiceStack - 對人路線的人員必須開始一個「/」
Routes.AddFromAssembly(typeof(PersonsService).Assembly);
的程序編譯,但是當我運行它我得到的錯誤(人是我的DTO):
Route Persons on Persons must start with a '/'
我搜索上ServiceStack的Git ServiceRoutesExtensions類,並在我的解決方案導入。我發現它有方法
private static void AddRoute(this IServiceRoutes routes, Type requestType, string allowedVerbs)
我調試了這個方法,發現requestType參數之前沒有「/」; routes.Add的元數據中的簽名是
IServiceRoutes Add(Type requestType, string restPath, string verbs);
所以,restPath參數映射到requestType.Name:
private static void AddRoute(this IServiceRoutes routes, Type requestType, string allowedVerbs)
{
routes.Add(requestType, requestType.Name, allowedVerbs);
var hasIdField = requestType.GetProperty(IdUtils.IdField) != null;
if (!hasIdField) return;
var routePath = requestType.Name + "/{" + IdUtils.IdField + "}";
routes.Add(requestType, routePath, allowedVerbs);
}
我修改的方法是:
private static void AddRoute(this IServiceRoutes routes, Type requestType, string allowedVerbs)
{
routes.Add(requestType, "/" + requestType.Name.ToLower(), allowedVerbs);
var hasIdField = requestType.GetProperty(IdUtils.IdField) != null;
if (!hasIdField) return;
var routePath = "/" + requestType.Name.ToLower() + "/{" + IdUtils.IdField + "}";
routes.Add(requestType, routePath, allowedVerbs);
}
現在一切工作正常,但我不知道我是否錯過了一些東西。
你有沒有機會將此修復推送到NuGet? –