我们已经将项目升级到asp.net core 3.0,并希望使用端点路由。
我有以下旧方法:
public static IRouteBuilder MapLocalizedRoute(this IRouteBuilder routeBuilder,
string name, string template, object defaults, object constraints, object dataTokens)
{
if (routeBuilder.DefaultHandler == null)
{
throw new ArgumentNullException(nameof(routeBuilder));
}
//get registered InlineConstraintResolver
var inlineConstraintResolver = routeBuilder.ServiceProvider.GetRequiredService<IInlineConstraintResolver>();
//create new generic route
routeBuilder.Routes.Add(new LocalizedRoute(routeBuilder.DefaultHandler, name, template,
new RouteValueDictionary(defaults), new RouteValueDictionary(constraints),
new RouteValueDictionary(dataTokens), inlineConstraintResolver));
return routeBuilder;
}
我需要更改以键入此IEndpointRouteBuilder routeBuilder 。 但是我如何实现添加新的通用路由器呢?接口IEndpointRouteBuilder的主体具有路由属性,我不能使用 routeBuilder.Routes.Add ...