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 1
1
// REF: https://github.com/aspnet/Entropy/blob/dev/samples/Mvc.CustomRoutingConvention/NameSpaceRoutingConvention.cs
2
2
// REF: https://github.com/aspnet/Mvc/issues/5691
3
+ using JsonApiDotNetCore . Controllers ;
3
4
using JsonApiDotNetCore . Extensions ;
4
5
using Microsoft . AspNetCore . Mvc . ApplicationModels ;
5
6
@@ -12,17 +13,28 @@ public DasherizedRoutingConvention(string nspace)
12
13
{
13
14
_namespace = nspace ;
14
15
}
15
-
16
+
16
17
public void Apply ( ApplicationModel application )
17
18
{
18
19
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 ) )
22
22
{
23
- Template = template
24
- } ;
23
+ var template = $ "{ _namespace } /{ controller . ControllerName . Dasherize ( ) } ";
24
+ controller . Selectors [ 0 ] . AttributeRouteModel = new AttributeRouteModel ( )
25
+ {
26
+ Template = template
27
+ } ;
28
+ }
25
29
}
26
30
}
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
+ }
27
39
}
28
40
}
You can’t perform that action at this time.
0 commit comments