我有这样的API路由属性类public class MyRouteAttribute : RouteAttribute{ private const string BaseRoute = "api/default"; private const string PrefixRouteBase = BaseRoute + "/"; public MyRouteAttribute() : base(BaseRoute) { } public MyRouteAttribute(string route): base(string.IsNullOrEmpty(route) ? BaseRoute : PrefixRouteBase + route) { }}并用在像这样的控制器中[MyRoute]public class MyController : Controller{ .....}IOptions如果必须使路由可配置,如何传递到MyRoute?例如,如果我这样做:public class MyRouteAttribute : RouteAttribute{ private const string BaseRoute = "api/default"; public MyRouteAttribute(IOptions<ApiRouteBaseConfiguration> routeOptions) : base(routeOptions.Value.Url) { } public MyRouteAttribute(IOptions<ApiRouteBaseConfiguration> routeOptions, string route): base(string.IsNullOrEmpty(route) ? (routeOptions.Value.Url: $"{routeOptions.Value.Url}/" + route) { }}然后我在这里出现错误,[MyRoute]要求我通过IOptions。如何在MyRoute属性中访问配置
1 回答
- 1 回答
- 0 关注
- 199 浏览
添加回答
举报
0/150
提交
取消