Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8570b21

Browse files
Merge pull request #428 from json-api-dotnet/rename-context-graph
rename contextGraph to resourceGraph
2 parents cbc37d1 + 2547678 commit 8570b21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+466
-451
lines changed

‎benchmarks/Serialization/JsonApiDeserializer_Benchmarks.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public class JsonApiDeserializer_Benchmarks {
3232
private readonly JsonApiDeSerializer _jsonApiDeSerializer;
3333

3434
public JsonApiDeserializer_Benchmarks() {
35-
var contextGraphBuilder = new ContextGraphBuilder();
36-
contextGraphBuilder.AddResource<SimpleType>(TYPE_NAME);
37-
var contextGraph = contextGraphBuilder.Build();
35+
var resourceGraphBuilder = new ResourceGraphBuilder();
36+
resourceGraphBuilder.AddResource<SimpleType>(TYPE_NAME);
37+
var resourceGraph = resourceGraphBuilder.Build();
3838

3939
var jsonApiContextMock = new Mock<IJsonApiContext>();
4040
jsonApiContextMock.SetupAllProperties();
41-
jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph);
41+
jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph);
4242
jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary<AttrAttribute, object>());
4343

4444
var jsonApiOptions = new JsonApiOptions();

‎benchmarks/Serialization/JsonApiSerializer_Benchmarks.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ public class JsonApiSerializer_Benchmarks {
1919
private readonly JsonApiSerializer _jsonApiSerializer;
2020

2121
public JsonApiSerializer_Benchmarks() {
22-
var contextGraphBuilder = new ContextGraphBuilder();
23-
contextGraphBuilder.AddResource<SimpleType>(TYPE_NAME);
24-
var contextGraph = contextGraphBuilder.Build();
22+
var resourceGraphBuilder = new ResourceGraphBuilder();
23+
resourceGraphBuilder.AddResource<SimpleType>(TYPE_NAME);
24+
var resourceGraph = resourceGraphBuilder.Build();
2525

2626
var jsonApiContextMock = new Mock<IJsonApiContext>();
2727
jsonApiContextMock.SetupAllProperties();
28-
jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph);
28+
jsonApiContextMock.Setup(m => m.ResourceGraph).Returns(resourceGraph);
2929
jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary<AttrAttribute, object>());
3030

3131
var jsonApiOptions = new JsonApiOptions();

‎src/Examples/NoEntityFrameworkExample/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public virtual IServiceProvider ConfigureServices(IServiceCollection services)
3535

3636
services.AddJsonApi(options => {
3737
options.Namespace = "api/v1";
38-
options.BuildContextGraph((builder) => {
38+
options.BuildResourceGraph((builder) => {
3939
builder.AddResource<TodoItem>("custom-todo-items");
4040
});
4141
}, mvcBuilder);

‎src/Examples/ResourceEntitySeparationExample/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public virtual IServiceProvider ConfigureServices(IServiceCollection services)
4949
options.Namespace = "api/v1";
5050
options.DefaultPageSize = 10;
5151
options.IncludeTotalRecordCount = true;
52-
options.BuildContextGraph((builder) => {
52+
options.BuildResourceGraph((builder) => {
5353
builder.AddResource<CourseResource>("courses");
5454
builder.AddResource<DepartmentResource>("departments");
5555
builder.AddResource<StudentResource>("students");

‎src/JsonApiDotNetCore/Builders/ContextGraphBuilder.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
namespace JsonApiDotNetCore.Builders
1515
{
16-
public interface IContextGraphBuilder
16+
public interface IResourceGraphBuilder
1717
{
1818
/// <summary>
19-
/// Construct the <see cref="ContextGraph"/>
19+
/// Construct the <see cref="ResourceGraph"/>
2020
/// </summary>
21-
IContextGraph Build();
21+
IResourceGraph Build();
2222

2323
/// <summary>
2424
/// Add a json:api resource
@@ -29,7 +29,7 @@ public interface IContextGraphBuilder
2929
/// If nothing is specified, the configured name formatter will be used.
3030
/// See <see cref="JsonApiOptions.ResourceNameFormatter" />.
3131
/// </param>
32-
IContextGraphBuilder AddResource<TResource>(string pluralizedTypeName = null) where TResource : class, IIdentifiable<int>;
32+
IResourceGraphBuilder AddResource<TResource>(string pluralizedTypeName = null) where TResource : class, IIdentifiable<int>;
3333

3434
/// <summary>
3535
/// Add a json:api resource
@@ -41,7 +41,7 @@ public interface IContextGraphBuilder
4141
/// If nothing is specified, the configured name formatter will be used.
4242
/// See <see cref="JsonApiOptions.ResourceNameFormatter" />.
4343
/// </param>
44-
IContextGraphBuilder AddResource<TResource, TId>(string pluralizedTypeName = null) where TResource : class, IIdentifiable<TId>;
44+
IResourceGraphBuilder AddResource<TResource, TId>(string pluralizedTypeName = null) where TResource : class, IIdentifiable<TId>;
4545

4646
/// <summary>
4747
/// Add a json:api resource
@@ -53,28 +53,28 @@ public interface IContextGraphBuilder
5353
/// If nothing is specified, the configured name formatter will be used.
5454
/// See <see cref="JsonApiOptions.ResourceNameFormatter" />.
5555
/// </param>
56-
IContextGraphBuilder AddResource(Type entityType, Type idType, string pluralizedTypeName = null);
56+
IResourceGraphBuilder AddResource(Type entityType, Type idType, string pluralizedTypeName = null);
5757

5858
/// <summary>
5959
/// Add all the models that are part of the provided <see cref="DbContext" />
6060
/// that also implement <see cref="IIdentifiable"/>
6161
/// </summary>
6262
/// <typeparam name="T">The <see cref="DbContext"/> implementation type.</typeparam>
63-
IContextGraphBuilder AddDbContext<T>() where T : DbContext;
63+
IResourceGraphBuilder AddDbContext<T>() where T : DbContext;
6464

6565
/// <summary>
6666
/// Specify the <see cref="IResourceNameFormatter"/> used to format resource names.
6767
/// </summary>
6868
/// <param name="resourceNameFormatter">Formatter used to define exposed resource names by convention.</param>
69-
IContextGraphBuilder UseNameFormatter(IResourceNameFormatter resourceNameFormatter);
69+
IResourceGraphBuilder UseNameFormatter(IResourceNameFormatter resourceNameFormatter);
7070

7171
/// <summary>
7272
/// Which links to include. Defaults to <see cref="Link.All"/>.
7373
/// </summary>
7474
Link DocumentLinks { get; set; }
7575
}
7676

77-
public class ContextGraphBuilder : IContextGraphBuilder
77+
public class ResourceGraphBuilder : IResourceGraphBuilder
7878
{
7979
private List<ContextEntity> _entities = new List<ContextEntity>();
8080
private List<ValidationResult> _validationResults = new List<ValidationResult>();
@@ -83,25 +83,25 @@ public class ContextGraphBuilder : IContextGraphBuilder
8383

8484
public Link DocumentLinks { get; set; } = Link.All;
8585

86-
public IContextGraph Build()
86+
public IResourceGraph Build()
8787
{
8888
// this must be done at build so that call order doesn't matter
8989
_entities.ForEach(e => e.Links = GetLinkFlags(e.EntityType));
9090

91-
var graph = new ContextGraph(_entities, _usesDbContext, _validationResults);
91+
var graph = new ResourceGraph(_entities, _usesDbContext, _validationResults);
9292
return graph;
9393
}
9494

9595
/// <inheritdoc />
96-
public IContextGraphBuilder AddResource<TResource>(string pluralizedTypeName = null) where TResource : class, IIdentifiable<int>
96+
public IResourceGraphBuilder AddResource<TResource>(string pluralizedTypeName = null) where TResource : class, IIdentifiable<int>
9797
=> AddResource<TResource, int>(pluralizedTypeName);
9898

9999
/// <inheritdoc />
100-
public IContextGraphBuilder AddResource<TResource, TId>(string pluralizedTypeName = null) where TResource : class, IIdentifiable<TId>
100+
public IResourceGraphBuilder AddResource<TResource, TId>(string pluralizedTypeName = null) where TResource : class, IIdentifiable<TId>
101101
=> AddResource(typeof(TResource), typeof(TId), pluralizedTypeName);
102102

103103
/// <inheritdoc />
104-
public IContextGraphBuilder AddResource(Type entityType, Type idType, string pluralizedTypeName = null)
104+
public IResourceGraphBuilder AddResource(Type entityType, Type idType, string pluralizedTypeName = null)
105105
{
106106
AssertEntityIsNotAlreadyDefined(entityType);
107107

@@ -222,7 +222,7 @@ protected virtual Type GetRelationshipType(RelationshipAttribute relation, Prope
222222
private Type GetResourceDefinitionType(Type entityType) => typeof(ResourceDefinition<>).MakeGenericType(entityType);
223223

224224
/// <inheritdoc />
225-
public IContextGraphBuilder AddDbContext<T>() where T : DbContext
225+
public IResourceGraphBuilder AddDbContext<T>() where T : DbContext
226226
{
227227
_usesDbContext = true;
228228

@@ -290,7 +290,7 @@ private void AssertEntityIsNotAlreadyDefined(Type entityType)
290290
}
291291

292292
/// <inheritdoc />
293-
public IContextGraphBuilder UseNameFormatter(IResourceNameFormatter resourceNameFormatter)
293+
public IResourceGraphBuilder UseNameFormatter(IResourceNameFormatter resourceNameFormatter)
294294
{
295295
_resourceNameFormatter = resourceNameFormatter;
296296
return this;

‎src/JsonApiDotNetCore/Builders/DocumentBuilder.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace JsonApiDotNetCore.Builders
1212
public class DocumentBuilder : IDocumentBuilder
1313
{
1414
private readonly IJsonApiContext _jsonApiContext;
15-
private readonly IContextGraph_contextGraph;
15+
private readonly IResourceGraph_resourceGraph;
1616
private readonly IRequestMeta _requestMeta;
1717
private readonly DocumentBuilderOptions _documentBuilderOptions;
1818
private readonly IScopedServiceProvider _scopedServiceProvider;
@@ -24,15 +24,15 @@ public DocumentBuilder(
2424
IScopedServiceProvider scopedServiceProvider = null)
2525
{
2626
_jsonApiContext = jsonApiContext;
27-
_contextGraph = jsonApiContext.ContextGraph;
27+
_resourceGraph = jsonApiContext.ResourceGraph;
2828
_requestMeta = requestMeta;
2929
_documentBuilderOptions = documentBuilderOptionsProvider?.GetDocumentBuilderOptions() ?? new DocumentBuilderOptions();
3030
_scopedServiceProvider = scopedServiceProvider;
3131
}
3232

3333
public Document Build(IIdentifiable entity)
3434
{
35-
var contextEntity = _contextGraph.GetContextEntity(entity.GetType());
35+
var contextEntity = _resourceGraph.GetContextEntity(entity.GetType());
3636

3737
var resourceDefinition = _scopedServiceProvider?.GetService(contextEntity.ResourceType) as IResourceDefinition;
3838
var document = new Document
@@ -52,7 +52,7 @@ public Document Build(IIdentifiable entity)
5252
public Documents Build(IEnumerable<IIdentifiable> entities)
5353
{
5454
var entityType = entities.GetElementType();
55-
var contextEntity = _contextGraph.GetContextEntity(entityType);
55+
var contextEntity = _resourceGraph.GetContextEntity(entityType);
5656
var resourceDefinition = _scopedServiceProvider?.GetService(contextEntity.ResourceType) as IResourceDefinition;
5757

5858
var enumeratedEntities = entities as IList<IIdentifiable> ?? entities.ToList();
@@ -179,7 +179,7 @@ private RelationshipData GetRelationshipData(RelationshipAttribute attr, Context
179179
}
180180

181181
// this only includes the navigation property, we need to actually check the navigation property Id
182-
var navigationEntity = _jsonApiContext.ContextGraph.GetRelationshipValue(entity, attr);
182+
var navigationEntity = _jsonApiContext.ResourceGraph.GetRelationshipValue(entity, attr);
183183
if (navigationEntity == null)
184184
relationshipData.SingleData = attr.IsHasOne
185185
? GetIndependentRelationshipIdentifier((HasOneAttribute)attr, entity)
@@ -217,7 +217,7 @@ private List<ResourceObject> IncludeRelationshipChain(
217217
if(relationship == null)
218218
throw new JsonApiException(400, $"{parentEntity.EntityName} does not contain relationship {requestedRelationship}");
219219

220-
var navigationEntity = _jsonApiContext.ContextGraph.GetRelationshipValue(parentResource, relationship);
220+
var navigationEntity = _jsonApiContext.ResourceGraph.GetRelationshipValue(parentResource, relationship);
221221
if (navigationEntity is IEnumerable hasManyNavigationEntity)
222222
{
223223
foreach (IIdentifiable includedEntity in hasManyNavigationEntity)
@@ -240,7 +240,7 @@ private List<ResourceObject> IncludeSingleResourceRelationships(
240240
{
241241
if (relationshipChainIndex < relationshipChain.Length)
242242
{
243-
var nextContextEntity = _jsonApiContext.ContextGraph.GetContextEntity(relationship.Type);
243+
var nextContextEntity = _jsonApiContext.ResourceGraph.GetContextEntity(relationship.Type);
244244
var resource = (IIdentifiable)navigationEntity;
245245
// recursive call
246246
if (relationshipChainIndex < relationshipChain.Length - 1)
@@ -271,7 +271,7 @@ private ResourceObject GetIncludedEntity(IIdentifiable entity)
271271
{
272272
if (entity == null) return null;
273273

274-
var contextEntity = _jsonApiContext.ContextGraph.GetContextEntity(entity.GetType());
274+
var contextEntity = _jsonApiContext.ResourceGraph.GetContextEntity(entity.GetType());
275275
var resourceDefinition = _scopedServiceProvider.GetService(contextEntity.ResourceType) as IResourceDefinition;
276276

277277
var data = GetData(contextEntity, entity, resourceDefinition);
@@ -296,7 +296,7 @@ private List<ResourceIdentifierObject> GetRelationships(IEnumerable<object> enti
296296
// so, we just lookup the type of the first entity on the graph
297297
// this is better than trying to get it from the generic parameter since it could
298298
// be less specific than what is registered on the graph (e.g. IEnumerable<object>)
299-
typeName = typeName ?? _jsonApiContext.ContextGraph.GetContextEntity(entity.GetType()).EntityName;
299+
typeName = typeName ?? _jsonApiContext.ResourceGraph.GetContextEntity(entity.GetType()).EntityName;
300300
relationships.Add(new ResourceIdentifierObject
301301
{
302302
Type = typeName,
@@ -309,7 +309,7 @@ private List<ResourceIdentifierObject> GetRelationships(IEnumerable<object> enti
309309
private ResourceIdentifierObject GetRelationship(object entity)
310310
{
311311
var objType = entity.GetType();
312-
var contextEntity = _jsonApiContext.ContextGraph.GetContextEntity(objType);
312+
var contextEntity = _jsonApiContext.ResourceGraph.GetContextEntity(objType);
313313

314314
if (entity is IIdentifiable identifiableEntity)
315315
return new ResourceIdentifierObject
@@ -327,7 +327,7 @@ private ResourceIdentifierObject GetIndependentRelationshipIdentifier(HasOneAttr
327327
if (independentRelationshipIdentifier == null)
328328
return null;
329329

330-
var relatedContextEntity = _jsonApiContext.ContextGraph.GetContextEntity(hasOne.Type);
330+
var relatedContextEntity = _jsonApiContext.ResourceGraph.GetContextEntity(hasOne.Type);
331331
if (relatedContextEntity == null) // TODO: this should probably be a debug log at minimum
332332
return null;
333333

‎src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class JsonApiOptions
7777
/// <summary>
7878
/// The graph of all resources exposed by this application.
7979
/// </summary>
80-
public IContextGraphContextGraph { get; set; }
80+
public IResourceGraphResourceGraph { get; set; }
8181

8282
/// <summary>
8383
/// Use relative links for all resources.
@@ -158,28 +158,28 @@ public IContractResolver JsonContractResolver
158158
ContractResolver = new DasherizedResolver()
159159
};
160160

161-
public void BuildContextGraph<TContext>(Action<IContextGraphBuilder> builder) where TContext : DbContext
161+
public void BuildResourceGraph<TContext>(Action<IResourceGraphBuilder> builder) where TContext : DbContext
162162
{
163-
BuildContextGraph(builder);
163+
BuildResourceGraph(builder);
164164

165-
ContextGraphBuilder.AddDbContext<TContext>();
165+
ResourceGraphBuilder.AddDbContext<TContext>();
166166

167-
ContextGraph = ContextGraphBuilder.Build();
167+
ResourceGraph = ResourceGraphBuilder.Build();
168168
}
169169

170-
public void BuildContextGraph(Action<IContextGraphBuilder> builder)
170+
public void BuildResourceGraph(Action<IResourceGraphBuilder> builder)
171171
{
172172
if (builder == null) return;
173173

174-
builder(ContextGraphBuilder);
174+
builder(ResourceGraphBuilder);
175175

176-
ContextGraph = ContextGraphBuilder.Build();
176+
ResourceGraph = ResourceGraphBuilder.Build();
177177
}
178178

179179
public void EnableExtension(JsonApiExtension extension)
180180
=> EnabledExtensions.Add(extension);
181181

182-
internal IContextGraphBuilderContextGraphBuilder { get; } = new ContextGraphBuilder();
182+
internal IResourceGraphBuilderResourceGraphBuilder { get; } = new ResourceGraphBuilder();
183183
internal List<JsonApiExtension> EnabledExtensions { get; set; } = new List<JsonApiExtension>();
184184
}
185185
}

‎src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public virtual async Task<IActionResult> PostAsync([FromBody] T entity)
156156
return Forbidden();
157157

158158
if (_jsonApiContext.Options.ValidateModelState && !ModelState.IsValid)
159-
return UnprocessableEntity(ModelState.ConvertToErrorCollection<T>(_jsonApiContext.ContextGraph));
159+
return UnprocessableEntity(ModelState.ConvertToErrorCollection<T>(_jsonApiContext.ResourceGraph));
160160

161161
entity = await _create.CreateAsync(entity);
162162

@@ -171,7 +171,7 @@ public virtual async Task<IActionResult> PatchAsync(TId id, [FromBody] T entity)
171171
return UnprocessableEntity();
172172

173173
if (_jsonApiContext.Options.ValidateModelState && !ModelState.IsValid)
174-
return UnprocessableEntity(ModelState.ConvertToErrorCollection<T>(_jsonApiContext.ContextGraph));
174+
return UnprocessableEntity(ModelState.ConvertToErrorCollection<T>(_jsonApiContext.ResourceGraph));
175175

176176
var updatedEntity = await _update.UpdateAsync(id, entity);
177177

‎src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public virtual IQueryable<TEntity> Include(IQueryable<TEntity> entities, string
317317
: $"{internalRelationshipPath}.{relationship.RelationshipPath}";
318318

319319
if(i < relationshipChain.Length)
320-
entity = _jsonApiContext.ContextGraph.GetContextEntity(relationship.Type);
320+
entity = _jsonApiContext.ResourceGraph.GetContextEntity(relationship.Type);
321321
}
322322

323323
return entities.Include(internalRelationshipPath);

‎src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static class IApplicationBuilderExtensions
1414
public static IApplicationBuilder UseJsonApi(this IApplicationBuilder app, bool useMvc = true)
1515
{
1616
DisableDetailedErrorsIfProduction(app);
17-
LogContextGraphValidations(app);
17+
LogResourceGraphValidations(app);
1818

1919
app.UseMiddleware<RequestMiddleware>();
2020

@@ -35,14 +35,14 @@ private static void DisableDetailedErrorsIfProduction(IApplicationBuilder app)
3535
}
3636
}
3737

38-
private static void LogContextGraphValidations(IApplicationBuilder app)
38+
private static void LogResourceGraphValidations(IApplicationBuilder app)
3939
{
40-
var logger = app.ApplicationServices.GetService(typeof(ILogger<ContextGraphBuilder>)) as ILogger;
41-
var contextGraph = app.ApplicationServices.GetService(typeof(IContextGraph)) as ContextGraph;
40+
var logger = app.ApplicationServices.GetService(typeof(ILogger<ResourceGraphBuilder>)) as ILogger;
41+
var resourceGraph = app.ApplicationServices.GetService(typeof(IResourceGraph)) as ResourceGraph;
4242

43-
if (logger != null && contextGraph != null)
43+
if (logger != null && resourceGraph != null)
4444
{
45-
contextGraph.ValidationResults.ForEach((v) =>
45+
resourceGraph.ValidationResults.ForEach((v) =>
4646
logger.Log(
4747
v.LogLevel,
4848
new EventId(),

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /