4
4
using Example . Api . Repositories ;
5
5
using Example . Api . Resources ;
6
6
using Example . Api . Services ;
7
- using JsonApiDotNetCore . Data ;
8
- using JsonApiDotNetCore . Extensions ;
9
- using JsonApiDotNetCore . Models ;
10
- using JsonApiDotNetCore . Services ;
7
+ using JsonApiDotNetCore . Configuration ;
8
+ using JsonApiDotNetCore . Resources ;
9
+ using JsonApiDotNetCore . Resources . Annotations ;
11
10
using Microsoft . AspNetCore . Builder ;
12
11
using Microsoft . AspNetCore . Hosting ;
13
12
using Microsoft . EntityFrameworkCore ;
14
13
using Microsoft . Extensions . DependencyInjection ;
14
+ using Microsoft . Extensions . Hosting ;
15
15
using Newtonsoft . Json ;
16
+ using Newtonsoft . Json . Serialization ;
16
17
17
18
namespace Example . Api
18
19
{
@@ -31,29 +32,39 @@ public void ConfigureServices(IServiceCollection services)
31
32
32
33
services . AddJsonApi < AppDbContext > ( options =>
33
34
{
34
- options . IncludeTotalRecordCount = true ;
35
+ options . IncludeTotalResourceCount = true ;
35
36
options . Namespace = "api" ;
36
- options . RelativeLinks = true ;
37
+ options . UseRelativeLinks = true ;
37
38
options . SerializerSettings . Formatting = Formatting . Indented ;
38
- options . DefaultPageSize = 10 ;
39
+ options . DefaultPageSize = new PageSize ( 10 ) ;
40
+ options . EnableLegacyFilterNotation = true ;
41
+ options . TopLevelLinks = LinkTypes . Paging ;
42
+ options . ResourceLinks = LinkTypes . None ;
43
+
44
+ options . SerializerSettings . ContractResolver = new DefaultContractResolver
45
+ {
46
+ NamingStrategy = new KebabCaseNamingStrategy ( )
47
+ } ;
39
48
} ) ;
40
49
41
- services . AddScoped < IEntityRepository < Person > , PersonRepository > ( ) ;
42
- services . AddScoped < IResourceService < Book > , BookService > ( ) ;
43
- services . AddScoped < ResourceDefinition < Book > , BookDefinition > ( ) ;
50
+ services . AddResourceRepository < PersonRepository > ( ) ;
51
+ services . AddResourceService < BookService > ( ) ;
52
+ services . AddScoped < IResourceDefinition < Book > , BookDefinition > ( ) ;
44
53
}
45
54
46
55
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
47
- public void Configure ( IApplicationBuilder app , IHostingEnvironment env , AppDbContext appDbContext )
56
+ public void Configure ( IApplicationBuilder app , IWebHostEnvironment environment , AppDbContext appDbContext )
48
57
{
49
58
SeedSampleData ( appDbContext ) ;
50
59
51
- if ( env . IsDevelopment ( ) )
60
+ if ( environment . IsDevelopment ( ) )
52
61
{
53
62
app . UseDeveloperExceptionPage ( ) ;
54
63
}
55
64
65
+ app . UseRouting ( ) ;
56
66
app . UseJsonApi ( ) ;
67
+ app . UseEndpoints ( endpoints => endpoints . MapControllers ( ) ) ;
57
68
}
58
69
59
70
private static void SeedSampleData ( AppDbContext appDbContext )
0 commit comments