@@ -11,17 +11,24 @@ namespace JsonApiDotNetCore.Configuration
11
11
{
12
12
public class ResourceGraphBuilder
13
13
{
14
- private readonly IJsonApiOptions _options ;
15
14
private readonly ILogger < ResourceGraphBuilder > _logger ;
15
+ private readonly IJsonApiOptions _options ;
16
16
private readonly List < ResourceContext > _resources = new List < ResourceContext > ( ) ;
17
17
18
18
public ResourceGraphBuilder ( IJsonApiOptions options , ILoggerFactory loggerFactory )
19
19
{
20
+ if ( loggerFactory == null )
21
+ {
22
+ throw new ArgumentNullException ( nameof ( loggerFactory ) ) ;
23
+ }
24
+
25
+ _logger = loggerFactory . CreateLogger < ResourceGraphBuilder > ( ) ;
20
26
_options = options ?? throw new ArgumentNullException ( nameof ( options ) ) ;
21
- _logger = loggerFactory ? . CreateLogger < ResourceGraphBuilder > ( ) ;
22
27
}
23
28
24
- /// <inheritdoc />
29
+ /// <summary>
30
+ /// Constructs the <see cref="ResourceGraph"/>.
31
+ /// </summary>
25
32
public IResourceGraph Build ( )
26
33
{
27
34
_resources . ForEach ( SetResourceLinksOptions ) ;
@@ -39,15 +46,28 @@ private void SetResourceLinksOptions(ResourceContext resourceContext)
39
46
}
40
47
}
41
48
42
- /// <inheritdoc />
43
- public ResourceGraphBuilder Add < TResource > ( string publicName = null ) where TResource : class , IIdentifiable < int >
44
- => Add < TResource , int > ( publicName ) ;
45
-
46
- /// <inheritdoc />
49
+ /// <summary>
50
+ /// Adds a json:api resource to the resource graph.
51
+ /// </summary>
52
+ /// <typeparam name="TResource">The resource type.</typeparam>
53
+ /// <typeparam name="TId">The identifier type of the resource</typeparam>
54
+ /// <param name="publicName">
55
+ /// The name under which the resource is publicly exposed by the API.
56
+ /// If nothing is specified, the configured casing convention formatter will be applied.
57
+ /// </param>
47
58
public ResourceGraphBuilder Add < TResource , TId > ( string publicName = null ) where TResource : class , IIdentifiable < TId >
48
59
=> Add ( typeof ( TResource ) , typeof ( TId ) , publicName ) ;
60
+
61
+ /// <summary>
62
+ /// <see cref="Add{TResource,TId}(string)"/>
63
+ /// </summary>
64
+ public ResourceGraphBuilder Add < TResource > ( string publicName = null ) where TResource : class , IIdentifiable < int >
65
+ => Add < TResource , int > ( publicName ) ;
66
+
49
67
50
- /// <inheritdoc />
68
+ /// <summary>
69
+ /// <see cref="Add{TResource,TId}(string)"/>
70
+ /// </summary>
51
71
public ResourceGraphBuilder Add ( Type resourceType , Type idType = null , string publicName = null )
52
72
{
53
73
if ( resourceType == null ) throw new ArgumentNullException ( nameof ( resourceType ) ) ;
@@ -63,7 +83,7 @@ public ResourceGraphBuilder Add(Type resourceType, Type idType = null, string pu
63
83
}
64
84
else
65
85
{
66
- _logger ? . LogWarning ( $ "Entity '{ resourceType } ' does not implement '{ nameof ( IIdentifiable ) } '.") ;
86
+ _logger . LogWarning ( $ "Entity '{ resourceType } ' does not implement '{ nameof ( IIdentifiable ) } '.") ;
67
87
}
68
88
}
69
89
@@ -81,7 +101,7 @@ public ResourceGraphBuilder Add(Type resourceType, Type idType = null, string pu
81
101
ResourceDefinitionType = GetResourceDefinitionType ( resourceType )
82
102
} ;
83
103
84
- protected virtual IReadOnlyCollection < AttrAttribute > GetAttributes ( Type resourceType )
104
+ private IReadOnlyCollection < AttrAttribute > GetAttributes ( Type resourceType )
85
105
{
86
106
if ( resourceType == null ) throw new ArgumentNullException ( nameof ( resourceType ) ) ;
87
107
@@ -122,7 +142,7 @@ protected virtual IReadOnlyCollection<AttrAttribute> GetAttributes(Type resource
122
142
return attributes ;
123
143
}
124
144
125
- protected virtual IReadOnlyCollection < RelationshipAttribute > GetRelationships ( Type resourceType )
145
+ private IReadOnlyCollection < RelationshipAttribute > GetRelationships ( Type resourceType )
126
146
{
127
147
if ( resourceType == null ) throw new ArgumentNullException ( nameof ( resourceType ) ) ;
128
148
@@ -180,7 +200,7 @@ protected virtual IReadOnlyCollection<RelationshipAttribute> GetRelationships(Ty
180
200
return attributes ;
181
201
}
182
202
183
- private static Type TryGetThroughType ( PropertyInfo throughProperty )
203
+ private Type TryGetThroughType ( PropertyInfo throughProperty )
184
204
{
185
205
if ( throughProperty . PropertyType . IsGenericType )
186
206
{
@@ -198,7 +218,7 @@ private static Type TryGetThroughType(PropertyInfo throughProperty)
198
218
return null ;
199
219
}
200
220
201
- protected virtual Type GetRelationshipType ( RelationshipAttribute relationship , PropertyInfo property )
221
+ private Type GetRelationshipType ( RelationshipAttribute relationship , PropertyInfo property )
202
222
{
203
223
if ( relationship == null ) throw new ArgumentNullException ( nameof ( relationship ) ) ;
204
224
if ( property == null ) throw new ArgumentNullException ( nameof ( property ) ) ;
@@ -231,7 +251,7 @@ private IReadOnlyCollection<EagerLoadAttribute> GetEagerLoads(Type resourceType,
231
251
return attributes ;
232
252
}
233
253
234
- private static Type TypeOrElementType ( Type type )
254
+ private Type TypeOrElementType ( Type type )
235
255
{
236
256
var interfaces = type . GetInterfaces ( )
237
257
. Where ( t => t . IsGenericType && t . GetGenericTypeDefinition ( ) == typeof ( IEnumerable < > ) ) . ToArray ( ) ;
0 commit comments