12
12
using JsonApiDotNetCore . Services . Operations . Processors ;
13
13
using Microsoft . AspNetCore . Http ;
14
14
using Microsoft . AspNetCore . Mvc ;
15
+ using Microsoft . AspNetCore . Mvc . Filters ;
15
16
using Microsoft . EntityFrameworkCore ;
16
17
using Microsoft . Extensions . DependencyInjection ;
17
18
@@ -44,12 +45,7 @@ public static IServiceCollection AddJsonApi<TContext>(this IServiceCollection se
44
45
45
46
config . BuildContextGraph ( builder => builder . AddDbContext < TContext > ( ) ) ;
46
47
47
- mvcBuilder
48
- . AddMvcOptions ( opt =>
49
- {
50
- opt . Filters . Add ( typeof ( JsonApiExceptionFilter ) ) ;
51
- opt . SerializeAsJsonApi ( config ) ;
52
- } ) ;
48
+ mvcBuilder . AddMvcOptions ( opt => AddMvcOptions ( opt , config ) ) ;
53
49
54
50
AddJsonApiInternals < TContext > ( services , config ) ;
55
51
return services ;
@@ -63,17 +59,19 @@ public static IServiceCollection AddJsonApi(this IServiceCollection services,
63
59
64
60
options ( config ) ;
65
61
66
- mvcBuilder
67
- . AddMvcOptions ( opt =>
68
- {
69
- opt . Filters . Add ( typeof ( JsonApiExceptionFilter ) ) ;
70
- opt . SerializeAsJsonApi ( config ) ;
71
- } ) ;
62
+ mvcBuilder . AddMvcOptions ( opt => AddMvcOptions ( opt , config ) ) ;
72
63
73
64
AddJsonApiInternals ( services , config ) ;
74
65
return services ;
75
66
}
76
67
68
+ private static void AddMvcOptions ( MvcOptions options , JsonApiOptions config )
69
+ {
70
+ options . Filters . Add ( typeof ( JsonApiExceptionFilter ) ) ;
71
+ options . Filters . Add ( typeof ( TypeMatchFilter ) ) ;
72
+ options . SerializeAsJsonApi ( config ) ;
73
+ }
74
+
77
75
public static void AddJsonApiInternals < TContext > (
78
76
this IServiceCollection services ,
79
77
JsonApiOptions jsonApiOptions ) where TContext : DbContext
@@ -141,6 +139,8 @@ public static void AddJsonApiInternals(
141
139
services . AddScoped < IQueryParser , QueryParser > ( ) ;
142
140
services . AddScoped < IControllerContext , Services . ControllerContext > ( ) ;
143
141
services . AddScoped < IDocumentBuilderOptionsProvider , DocumentBuilderOptionsProvider > ( ) ;
142
+
143
+ // services.AddScoped<IActionFilter, TypeMatchFilter>();
144
144
}
145
145
146
146
private static void AddOperationServices ( IServiceCollection services )
0 commit comments