File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed
src/JsonApiDotNetCore/Internal Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change 11// REF: https://github.com/aspnet/Entropy/blob/dev/samples/Mvc.CustomRoutingConvention/NameSpaceRoutingConvention.cs
22// REF: https://github.com/aspnet/Mvc/issues/5691
3+ using JsonApiDotNetCore . Controllers ;
34using JsonApiDotNetCore . Extensions ;
45using Microsoft . AspNetCore . Mvc . ApplicationModels ;
56
@@ -12,17 +13,28 @@ public DasherizedRoutingConvention(string nspace)
1213 {
1314 _namespace = nspace ;
1415 }
15-
16+
1617 public void Apply ( ApplicationModel application )
1718 {
1819 foreach ( var controller in application . Controllers )
19- {
20- var template = $ "{ _namespace } /{ controller . ControllerName . Dasherize ( ) } ";
21- controller . Selectors [ 0 ] . AttributeRouteModel = new AttributeRouteModel ( )
20+ {
21+ if ( IsJsonApiController ( controller ) )
2222 {
23- Template = template
24- } ;
23+ var template = $ "{ _namespace } /{ controller . ControllerName . Dasherize ( ) } ";
24+ controller . Selectors [ 0 ] . AttributeRouteModel = new AttributeRouteModel ( )
25+ {
26+ Template = template
27+ } ;
28+ }
2529 }
2630 }
31+
32+ private bool IsJsonApiController ( ControllerModel controller )
33+ {
34+ var controllerBaseType = controller . ControllerType . BaseType ;
35+ if ( ! controllerBaseType . IsConstructedGenericType ) return false ;
36+ var genericTypeDefinition = controllerBaseType . GetGenericTypeDefinition ( ) ;
37+ return ( genericTypeDefinition == typeof ( JsonApiController < , > ) || genericTypeDefinition == typeof ( JsonApiController < > ) ) ;
38+ }
2739 }
2840}
You can’t perform that action at this time.
0 commit comments