4
4
using FluentValidation . AspNetCore ;
5
5
using Microsoft . AspNetCore . Mvc ;
6
6
using Microsoft . Extensions . DependencyInjection ;
7
- using Newtonsoft . Json ;
8
7
using Newtonsoft . Json . Converters ;
9
8
using Newtonsoft . Json . Serialization ;
10
9
11
10
namespace ArchitectNow . Web . Configuration
12
11
{
13
12
public static class WebApiExtensions
14
13
{
15
- public static void ConfigureApi ( this IServiceCollection services , FluentValidationOptions fluentValidationOptions , Action < MvcOptions > configureMvc = null , Action < MvcJsonOptions > configureJson = null )
14
+ public static void ConfigureApi ( this IServiceCollection services , FluentValidationOptions fluentValidationOptions , Action < MvcOptions > configureMvc = null , Action < MvcJsonOptions > configureJson = null , Action < IMvcBuilder > configureMvcBuilder = null )
16
15
{
17
16
/*************************
18
17
* IConfiguration is not available yet
@@ -33,16 +32,14 @@ public static void ConfigureApi(this IServiceCollection services, FluentValidati
33
32
var camelCasePropertyNamesContractResolver = new CamelCasePropertyNamesContractResolver ( ) ;
34
33
35
34
settings . ContractResolver = camelCasePropertyNamesContractResolver ;
36
- settings . Converters = new JsonConverter [ ]
37
- {
38
- new IsoDateTimeConverter ( ) ,
39
- new StringEnumConverter ( true )
40
- } ;
35
+ settings . Converters . Add ( new IsoDateTimeConverter ( ) ) ;
36
+ settings . Converters . Add ( new StringEnumConverter ( true ) ) ;
41
37
42
38
configureJson ? . Invoke ( options ) ;
43
39
} ) ;
44
40
45
-
41
+ configureMvcBuilder ? . Invoke ( mvcBuilder ) ;
42
+
46
43
if ( fluentValidationOptions . Enabled )
47
44
{
48
45
mvcBuilder . AddFluentValidation ( configuration => fluentValidationOptions . Configure ? . Invoke ( configuration ) ) ;
0 commit comments