66using JsonApiDotNetCore . Internal ;
77using JsonApiDotNetCore . Internal . Generics ;
88using JsonApiDotNetCore . Middleware ;
9+ using JsonApiDotNetCore . Models ;
910using JsonApiDotNetCore . Serialization ;
1011using JsonApiDotNetCore . Services ;
12+ using JsonApiDotNetCore . Services . Operations ;
1113using Microsoft . AspNetCore . Http ;
1214using Microsoft . AspNetCore . Mvc ;
1315using Microsoft . EntityFrameworkCore ;
@@ -91,6 +93,9 @@ public static void AddJsonApiInternals(
9193 services . AddSingleton < DbContextOptions > ( new DbContextOptionsBuilder ( ) . Options ) ;
9294 }
9395
96+ if ( jsonApiOptions . EnabledExtensions . Contains ( JsonApiExtension . Operations ) )
97+ AddOperationServices ( services ) ;
98+
9499 services . AddScoped < IDbContextResolver , DbContextResolver > ( ) ;
95100 services . AddScoped ( typeof ( IEntityRepository < > ) , typeof ( DefaultEntityRepository < > ) ) ;
96101 services . AddScoped ( typeof ( IEntityRepository < , > ) , typeof ( DefaultEntityRepository < , > ) ) ;
@@ -114,8 +119,18 @@ public static void AddJsonApiInternals(
114119 services . AddScoped < IControllerContext , Services . ControllerContext > ( ) ;
115120 }
116121
122+ private static void AddOperationServices ( IServiceCollection services )
123+ {
124+ services . AddScoped < IOperationsProcessor , OperationsProcessor > ( ) ;
125+ services . AddSingleton < IOperationProcessorResolver , OperationProcessorResolver > ( ) ;
126+ services . AddSingleton < IGenericProcessorFactory , GenericProcessorFactory > ( ) ;
127+ }
128+
117129 public static void SerializeAsJsonApi ( this MvcOptions options , JsonApiOptions jsonApiOptions )
118130 {
131+ if ( jsonApiOptions . EnabledExtensions . Contains ( JsonApiExtension . Operations ) )
132+ options . InputFormatters . Insert ( 0 , new JsonApiOperationsInputFormatter ( ) ) ;
133+
119134 options . InputFormatters . Insert ( 0 , new JsonApiInputFormatter ( ) ) ;
120135
121136 options . OutputFormatters . Insert ( 0 , new JsonApiOutputFormatter ( ) ) ;
0 commit comments