|
6 | 6 | using Microsoft.EntityFrameworkCore; |
7 | 7 | using JsonApiDotNetCore.Extensions; |
8 | 8 | using System; |
| 9 | +using JsonApiDotNetCore.Configuration; |
9 | 10 | using JsonApiDotNetCore.Query; |
10 | 11 | using JsonApiDotNetCoreExample.Services; |
| 12 | +using Newtonsoft.Json.Converters; |
11 | 13 |
|
12 | 14 | namespace JsonApiDotNetCoreExample |
13 | 15 | { |
@@ -37,21 +39,24 @@ public virtual void ConfigureServices(IServiceCollection services) |
37 | 39 | .EnableSensitiveDataLogging() |
38 | 40 | .UseNpgsql(GetDbConnectionString(), innerOptions => innerOptions.SetPostgresVersion(new Version(9,6))); |
39 | 41 | }, ServiceLifetime.Transient) |
40 | | - .AddJsonApi(options => |
41 | | - { |
42 | | - options.IncludeExceptionStackTraceInErrors = true; |
43 | | - options.Namespace = "api/v1"; |
44 | | - options.DefaultPageSize = 5; |
45 | | - options.IncludeTotalRecordCount = true; |
46 | | - options.LoadDatabaseValues = true; |
47 | | - options.ValidateModelState = true; |
48 | | - options.EnableResourceHooks = true; |
49 | | - }, |
50 | | - discovery => discovery.AddCurrentAssembly()); |
| 42 | + .AddJsonApi(ConfigureJsonApiOptions, discovery => discovery.AddCurrentAssembly()); |
| 43 | + |
51 | 44 | // once all tests have been moved to WebApplicationFactory format we can get rid of this line below |
52 | 45 | services.AddClientSerialization(); |
53 | 46 | } |
54 | 47 |
|
| 48 | + protected virtual void ConfigureJsonApiOptions(JsonApiOptions options) |
| 49 | + { |
| 50 | + options.IncludeExceptionStackTraceInErrors = true; |
| 51 | + options.Namespace = "api/v1"; |
| 52 | + options.DefaultPageSize = 5; |
| 53 | + options.IncludeTotalRecordCount = true; |
| 54 | + options.LoadDatabaseValues = true; |
| 55 | + options.ValidateModelState = true; |
| 56 | + options.EnableResourceHooks = true; |
| 57 | + options.SerializerSettings.Converters.Add(new StringEnumConverter()); |
| 58 | + } |
| 59 | + |
55 | 60 | public void Configure( |
56 | 61 | IApplicationBuilder app, |
57 | 62 | AppDbContext context) |
|
0 commit comments