1
+ using System ;
2
+ using JsonApiDotNetCore . Configuration ;
1
3
using JsonApiDotNetCore . Data ;
2
4
using JsonApiDotNetCore . Formatters ;
3
5
using JsonApiDotNetCore . Internal ;
@@ -13,10 +15,24 @@ public static class ServiceProviderExtensions
13
15
{
14
16
public static void AddJsonApi < TContext > ( this IServiceCollection services )
15
17
where TContext : DbContext
18
+ {
19
+ _addInternals < TContext > ( services , new JsonApiOptions ( ) ) ;
20
+ }
21
+
22
+ public static void AddJsonApi < TContext > ( this IServiceCollection services , Action < JsonApiOptions > options )
23
+ where TContext : DbContext
24
+ {
25
+ var config = new JsonApiOptions ( ) ;
26
+ options ( config ) ;
27
+ _addInternals < TContext > ( services , config ) ;
28
+ }
29
+
30
+ private static void _addInternals < TContext > ( IServiceCollection services , JsonApiOptions jsonApiOptions )
31
+ where TContext : DbContext
16
32
{
17
33
services . AddJsonApiInternals < TContext > ( ) ;
18
34
services . AddMvc ( )
19
- . AddMvcOptions ( options => options . SerializeAsJsonApi ( ) ) ;
35
+ . AddMvcOptions ( opt => opt . SerializeAsJsonApi ( jsonApiOptions ) ) ;
20
36
}
21
37
22
38
public static void AddJsonApiInternals < TContext > ( this IServiceCollection services )
@@ -37,11 +53,13 @@ public static void AddJsonApiInternals<TContext>(this IServiceCollection service
37
53
services . AddScoped < JsonApiRouteHandler > ( ) ;
38
54
}
39
55
40
- public static void SerializeAsJsonApi ( this MvcOptions options )
56
+ public static void SerializeAsJsonApi ( this MvcOptions options , JsonApiOptions jsonApiOptions )
41
57
{
42
58
options . InputFormatters . Insert ( 0 , new JsonApiInputFormatter ( ) ) ;
43
59
44
60
options . OutputFormatters . Insert ( 0 , new JsonApiOutputFormatter ( ) ) ;
61
+
62
+ options . Conventions . Insert ( 0 , new DasherizedRoutingConvention ( jsonApiOptions . Namespace ) ) ;
45
63
}
46
64
}
47
65
}
0 commit comments