Skip to content

Commit a7618f6

Browse files
committed
style: rename IResourceGraphExplorer back to IResourceGraph, consitent usage of IContextEntityProvider
1 parent 95d8707 commit a7618f6

File tree

62 files changed

+182
-256
lines changed

Some content is hidden

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

62 files changed

+182
-256
lines changed

src/Examples/JsonApiDotNetCoreExample/Resources/ArticleResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JsonApiDotNetCoreExample.Resources
1111
{
1212
public class ArticleResource : ResourceDefinition<Article>
1313
{
14-
public ArticleResource(IResourceGraphExplorer graph) : base(graph) { }
14+
public ArticleResource(IResourceGraph resourceGraph) : base(resourceGraph) { }
1515

1616
public override IEnumerable<Article> OnReturn(HashSet<Article> entities, ResourcePipeline pipeline)
1717
{

src/Examples/JsonApiDotNetCoreExample/Resources/LockableResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JsonApiDotNetCoreExample.Resources
1111
{
1212
public abstract class LockableResource<T> : ResourceDefinition<T> where T : class, IIsLockable, IIdentifiable
1313
{
14-
protected LockableResource(IResourceGraphExplorer graph) : base(graph) { }
14+
protected LockableResource(IResourceGraph resourceGraph) : base(resourceGraph) { }
1515

1616
protected void DisallowLocked(IEnumerable<T> entities)
1717
{

src/Examples/JsonApiDotNetCoreExample/Resources/PassportResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JsonApiDotNetCoreExample.Resources
1111
{
1212
public class PassportResource : ResourceDefinition<Passport>
1313
{
14-
public PassportResource(IResourceGraphExplorer graph) : base(graph)
14+
public PassportResource(IResourceGraph resourceGraph) : base(resourceGraph)
1515
{
1616
}
1717

src/Examples/JsonApiDotNetCoreExample/Resources/PersonResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace JsonApiDotNetCoreExample.Resources
99
{
1010
public class PersonResource : LockableResource<Person>, IHasMeta
1111
{
12-
public PersonResource(IResourceGraphExplorer graph) : base(graph) { }
12+
public PersonResource(IResourceGraph resourceGraph) : base(resourceGraph) { }
1313

1414
public override IEnumerable<Person> BeforeUpdate(IDiffableEntityHashSet<Person> entities, ResourcePipeline pipeline)
1515
{

src/Examples/JsonApiDotNetCoreExample/Resources/TagResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace JsonApiDotNetCoreExample.Resources
1010
{
1111
public class TagResource : ResourceDefinition<Tag>
1212
{
13-
public TagResource(IResourceGraphExplorer graph) : base(graph) { }
13+
public TagResource(IResourceGraph resourceGraph) : base(resourceGraph) { }
1414

1515
public override IEnumerable<Tag> BeforeCreate(IEntityHashSet<Tag> affected, ResourcePipeline pipeline)
1616
{

src/Examples/JsonApiDotNetCoreExample/Resources/TodoResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace JsonApiDotNetCoreExample.Resources
1010
{
1111
public class TodoResource : LockableResource<TodoItem>
1212
{
13-
public TodoResource(IResourceGraphExplorer graph) : base(graph) { }
13+
public TodoResource(IResourceGraph resourceGraph) : base(resourceGraph) { }
1414

1515
public override void BeforeRead(ResourcePipeline pipeline, bool isIncluded = false, string stringId = null)
1616
{

src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace JsonApiDotNetCoreExample.Resources
99
{
1010
public class UserResource : ResourceDefinition<User>
1111
{
12-
public UserResource(IResourceGraphExplorer graph) : base(graph)
12+
public UserResource(IResourceGraph resourceGraph) : base(resourceGraph)
1313
{
1414
HideFields(u => u.Password);
1515
}

src/Examples/ReportsExample/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public virtual void ConfigureServices(IServiceCollection services)
2727
var mvcBuilder = services.AddMvcCore();
2828
services.AddJsonApi(
2929
opt => opt.Namespace = "api",
30-
discovery => discovery.AddCurrentAssembly(), mvcBuilder);
30+
discovery => discovery.AddCurrentAssembly(), mvcBuilder: mvcBuilder);
3131
}
3232

3333
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

src/JsonApiDotNetCore/Builders/IResourceGraphBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface IResourceGraphBuilder
1212
/// <summary>
1313
/// Construct the <see cref="ResourceGraph"/>
1414
/// </summary>
15-
IResourceGraphExplorer Build();
15+
IResourceGraph Build();
1616

1717
/// <summary>
1818
/// Add a json:api resource

src/JsonApiDotNetCore/Builders/JsonApiApplicationBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private void RegisterJsonApiStartupServices()
9494

9595
public void ConfigureServices()
9696
{
97-
var graph = _resourceGraphBuilder.Build();
97+
var resourceGraph = _resourceGraphBuilder.Build();
9898

9999
if (!_usesDbContext)
100100
{
@@ -130,10 +130,10 @@ public void ConfigureServices()
130130
_services.AddScoped(typeof(IResourceService<,>), typeof(EntityResourceService<,>));
131131

132132
_services.AddSingleton<ILinksConfiguration>(JsonApiOptions);
133-
_services.AddSingleton(graph);
133+
_services.AddSingleton(resourceGraph);
134134
_services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
135-
_services.AddSingleton<IResourceGraphExplorer>(graph);
136-
_services.AddSingleton<IContextEntityProvider>(graph);
135+
_services.AddSingleton<IResourceGraph>(resourceGraph);
136+
_services.AddSingleton<IContextEntityProvider>(resourceGraph);
137137
_services.AddScoped<ICurrentRequest, CurrentRequest>();
138138
_services.AddScoped<IScopedServiceProvider, RequestScopedServiceProvider>();
139139
_services.AddScoped<IJsonApiWriter, JsonApiWriter>();

src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public ResourceGraphBuilder(IResourceNameFormatter formatter)
2929
}
3030

3131
/// <inheritdoc />
32-
public IResourceGraphExplorer Build()
32+
public IResourceGraph Build()
3333
{
3434
_entities.ForEach(SetResourceLinksOptions);
35-
var graph = new ResourceGraph(_entities, _validationResults);
36-
return graph;
35+
var resourceGraph = new ResourceGraph(_entities, _validationResults);
36+
return resourceGraph;
3737
}
3838

3939
private void SetResourceLinksOptions(ContextEntity resourceContext)
@@ -235,7 +235,7 @@ private string GetResourceNameFromDbSetProperty(PropertyInfo property, Type reso
235235
private void AssertEntityIsNotAlreadyDefined(Type entityType)
236236
{
237237
if (_entities.Any(e => e.EntityType == entityType))
238-
throw new InvalidOperationException($"Cannot add entity type {entityType} to context graph, there is already an entity of that type configured.");
238+
throw new InvalidOperationException($"Cannot add entity type {entityType} to context resourceGraph, there is already an entity of that type configured.");
239239
}
240240
}
241241
}

src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@ public class DefaultEntityRepository<TEntity, TId> : IEntityRepository<TEntity,
2424
private readonly ITargetedFields _targetedFields;
2525
private readonly DbContext _context;
2626
private readonly DbSet<TEntity> _dbSet;
27-
private readonly IContextEntityProvider _provider;
27+
private readonly IResourceGraph _resourceGraph;
2828
private readonly IGenericProcessorFactory _genericProcessorFactory;
2929

3030
public DefaultEntityRepository(
3131
ITargetedFields targetedFields,
3232
IDbContextResolver contextResolver,
33-
IContextEntityProvider provider,
33+
IResourceGraph resourceGraph,
3434
IGenericProcessorFactory genericProcessorFactory)
35-
: this(targetedFields, contextResolver, provider, genericProcessorFactory, null)
35+
: this(targetedFields, contextResolver, resourceGraph, genericProcessorFactory, null)
3636
{ }
3737

3838
public DefaultEntityRepository(
3939
ITargetedFields targetedFields,
4040
IDbContextResolver contextResolver,
41-
IContextEntityProvider provider,
41+
IResourceGraph resourceGraph,
4242
IGenericProcessorFactory genericProcessorFactory,
4343
ILoggerFactory loggerFactory = null)
4444
{
4545
_targetedFields = targetedFields;
46-
_provider = provider;
46+
_resourceGraph = resourceGraph;
4747
_genericProcessorFactory = genericProcessorFactory;
4848
_context = contextResolver.GetContext();
4949
_dbSet = _context.Set<TEntity>();
@@ -137,7 +137,7 @@ private void LoadInverseRelationships(object trackedRelationshipValue, Relations
137137

138138
private bool IsHasOneRelationship(string internalRelationshipName, Type type)
139139
{
140-
var relationshipAttr = _provider.GetContextEntity(type).Relationships.FirstOrDefault(r => r.InternalRelationshipName == internalRelationshipName);
140+
var relationshipAttr = _resourceGraph.GetRelationships(type).FirstOrDefault(r => r.InternalRelationshipName == internalRelationshipName);
141141
if (relationshipAttr != null)
142142
{
143143
if (relationshipAttr is HasOneAttribute)
@@ -419,15 +419,15 @@ public class DefaultEntityRepository<TEntity> : DefaultEntityRepository<TEntity,
419419
{
420420
public DefaultEntityRepository(ITargetedFields targetedFields,
421421
IDbContextResolver contextResolver,
422-
IResourceGraphExplorer contextEntityProvider,
422+
IResourceGraph contextEntityProvider,
423423
IGenericProcessorFactory genericProcessorFactory)
424424
: base(targetedFields, contextResolver, contextEntityProvider, genericProcessorFactory)
425425
{
426426
}
427427

428428
public DefaultEntityRepository(ITargetedFields targetedFields,
429429
IDbContextResolver contextResolver,
430-
IResourceGraphExplorer contextEntityProvider,
430+
IResourceGraph contextEntityProvider,
431431
IGenericProcessorFactory genericProcessorFactory,
432432
ILoggerFactory loggerFactory = null)
433433
: base(targetedFields, contextResolver, contextEntityProvider, genericProcessorFactory, loggerFactory)

src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private static void DisableDetailedErrorsIfProduction(IApplicationBuilder app)
4949
private static void LogResourceGraphValidations(IApplicationBuilder app)
5050
{
5151
var logger = app.ApplicationServices.GetService(typeof(ILogger<ResourceGraphBuilder>)) as ILogger;
52-
var resourceGraph = app.ApplicationServices.GetService(typeof(IResourceGraphExplorer)) as ResourceGraph;
52+
var resourceGraph = app.ApplicationServices.GetService(typeof(IResourceGraph)) as ResourceGraph;
5353

5454
if (logger != null && resourceGraph != null)
5555
{

src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public static IServiceCollection AddClientSerialization(this IServiceCollection
8080

8181
services.AddScoped<IRequestSerializer>(sp =>
8282
{
83-
var resourceObjectBuilder = new ResourceObjectBuilder(sp.GetService<IResourceGraphExplorer>(), sp.GetService<IResourceObjectBuilderSettingsProvider>().Get());
84-
return new RequestSerializer(sp.GetService<IResourceGraphExplorer>(), resourceObjectBuilder);
83+
var resourceObjectBuilder = new ResourceObjectBuilder(sp.GetService<IResourceGraph>(), sp.GetService<IResourceObjectBuilderSettingsProvider>().Get());
84+
return new RequestSerializer(sp.GetService<IResourceGraph>(), resourceObjectBuilder);
8585
});
8686
return services;
8787
}

src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ public class ServiceDiscoveryFacade : IServiceDiscoveryFacade
4949
typeof(IEntityReadRepository<,>)
5050
};
5151
private readonly IServiceCollection _services;
52-
private readonly IResourceGraphBuilder _graphBuilder;
52+
private readonly IResourceGraphBuilder _resourceGraphBuilder;
5353
private readonly List<ResourceDescriptor> _identifiables = new List<ResourceDescriptor>();
5454

55-
public ServiceDiscoveryFacade(IServiceCollection services, IResourceGraphBuilder graphBuilder)
55+
public ServiceDiscoveryFacade(IServiceCollection services, IResourceGraphBuilder resourceGraphBuilder)
5656
{
5757
_services = services;
58-
_graphBuilder = graphBuilder;
58+
_resourceGraphBuilder = resourceGraphBuilder;
5959
}
6060

6161
/// <summary>
@@ -107,7 +107,7 @@ private void AddDbContextResolvers(Assembly assembly)
107107
}
108108

109109
/// <summary>
110-
/// Adds resources to the graph and registers <see cref="ResourceDefinition{T}"/> types on the container.
110+
/// Adds resources to the resourceGraph and registers <see cref="ResourceDefinition{T}"/> types on the container.
111111
/// </summary>
112112
/// <param name="assembly">The assembly to search for resources in.</param>
113113
public ServiceDiscoveryFacade AddResources(Assembly assembly)
@@ -144,7 +144,7 @@ private void RegisterResourceDefinition(Assembly assembly, ResourceDescriptor id
144144
private void AddResourceToGraph(ResourceDescriptor identifiable)
145145
{
146146
var resourceName = FormatResourceName(identifiable.ResourceType);
147-
_graphBuilder.AddResource(identifiable.ResourceType, identifiable.IdType, resourceName);
147+
_resourceGraphBuilder.AddResource(identifiable.ResourceType, identifiable.IdType, resourceName);
148148
}
149149

150150
private string FormatResourceName(Type resourceType)

src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ internal class ResourceHookExecutor : IResourceHookExecutor
2121
private readonly ITraversalHelper _traversalHelper;
2222
private readonly IIncludeService _includeService;
2323
private readonly ITargetedFields _targetedFields;
24-
private readonly IResourceGraphExplorer _inverseRelationships;
24+
private readonly IResourceGraph _inverseRelationships;
2525
public ResourceHookExecutor(
2626
IHookExecutorHelper executorHelper,
2727
ITraversalHelper traversalHelper,
2828
ITargetedFields targetedFields,
2929
IIncludeService includedRelationships,
30-
IResourceGraphExplorer graph)
30+
IResourceGraph resourceGraph)
3131
{
3232
_executorHelper = executorHelper;
3333
_traversalHelper = traversalHelper;
3434
_targetedFields = targetedFields;
3535
_includeService = includedRelationships;
36-
_inverseRelationships = graph;
36+
_inverseRelationships = resourceGraph;
3737
}
3838

3939
/// <inheritdoc/>

src/JsonApiDotNetCore/Hooks/Traversal/TraversalHelper.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace JsonApiDotNetCore.Hooks
2525
internal class TraversalHelper : ITraversalHelper
2626
{
2727
private readonly IdentifiableComparer _comparer = new IdentifiableComparer();
28-
private readonly IContextEntityProvider _provider;
28+
private readonly IResourceGraph _resourceGraph;
2929
private readonly ITargetedFields _targetedFields;
3030
/// <summary>
3131
/// Keeps track of which entities has already been traversed through, to prevent
@@ -38,11 +38,11 @@ internal class TraversalHelper : ITraversalHelper
3838
/// </summary>
3939
private readonly Dictionary<RelationshipAttribute, RelationshipProxy> RelationshipProxies = new Dictionary<RelationshipAttribute, RelationshipProxy>();
4040
public TraversalHelper(
41-
IContextEntityProvider provider,
41+
IResourceGraph resourceGraph,
4242
ITargetedFields targetedFields)
4343
{
4444
_targetedFields = targetedFields;
45-
_provider = provider;
45+
_resourceGraph = resourceGraph;
4646
}
4747

4848
/// <summary>
@@ -196,13 +196,12 @@ HashSet<TEntity> ProcessEntities<TEntity>(IEnumerable<TEntity> incomingEntities)
196196

197197
/// <summary>
198198
/// Parses all relationships from <paramref name="type"/> to
199-
/// other models in the resource graphs by constructing RelationshipProxies .
199+
/// other models in the resource resourceGraphs by constructing RelationshipProxies .
200200
/// </summary>
201201
/// <param name="type">The type to parse</param>
202202
void RegisterRelationshipProxies(DependentType type)
203203
{
204-
var contextEntity = _provider.GetContextEntity(type);
205-
foreach (RelationshipAttribute attr in contextEntity.Relationships)
204+
foreach (RelationshipAttribute attr in _resourceGraph.GetRelationships(type))
206205
{
207206
if (!attr.CanInclude) continue;
208207
if (!RelationshipProxies.TryGetValue(attr, out RelationshipProxy proxies))

src/JsonApiDotNetCore/Internal/Contracts/IContextEntityProvider.cs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,6 @@
66

77
namespace JsonApiDotNetCore.Internal.Contracts
88
{
9-
10-
/// <summary>
11-
/// Responsible for retrieving the exposed resource fields (attributes and
12-
/// relationships) of registered resources in the resource graph.
13-
/// </summary>
14-
public interface IResourceGraphExplorer : IContextEntityProvider
15-
{
16-
/// <summary>
17-
/// Gets all fields (attributes and relationships) for <typeparamref name="TResource"/>
18-
/// that are targeted by the selector. If no selector is provided, all
19-
/// exposed fields are returned.
20-
/// </summary>
21-
/// <typeparam name="TResource">The resource for which to retrieve fields</typeparam>
22-
/// <param name="selector">Should be of the form: (TResource e) => new { e.Field1, e.Field2 }</param>
23-
List<IResourceField> GetFields<TResource>(Expression<Func<TResource, dynamic>> selector = null) where TResource : IIdentifiable;
24-
/// <summary>
25-
/// Gets all attributes for <typeparamref name="TResource"/>
26-
/// that are targeted by the selector. If no selector is provided, all
27-
/// exposed fields are returned.
28-
/// </summary>
29-
/// <typeparam name="TResource">The resource for which to retrieve attributes</typeparam>
30-
/// <param name="selector">Should be of the form: (TResource e) => new { e.Attribute1, e.Arttribute2 }</param>
31-
List<AttrAttribute> GetAttributes<TResource>(Expression<Func<TResource, dynamic>> selector = null) where TResource : IIdentifiable;
32-
/// <summary>
33-
/// Gets all relationships for <typeparamref name="TResource"/>
34-
/// that are targeted by the selector. If no selector is provided, all
35-
/// exposed fields are returned.
36-
/// </summary>
37-
/// <typeparam name="TResource">The resource for which to retrieve relationships</typeparam>
38-
/// <param name="selector">Should be of the form: (TResource e) => new { e.Relationship1, e.Relationship2 }</param>
39-
List<RelationshipAttribute> GetRelationships<TResource>(Expression<Func<TResource, dynamic>> selector = null) where TResource : IIdentifiable;
40-
/// <summary>
41-
/// Gets all exposed fields (attributes and relationships) for type <paramref name="type"/>
42-
/// </summary>
43-
/// <param name="type">The resource type. Must extend IIdentifiable.</param>
44-
List<IResourceField> GetFields(Type type);
45-
/// <summary>
46-
/// Gets all exposed attributes for type <paramref name="type"/>
47-
/// </summary>
48-
/// <param name="type">The resource type. Must extend IIdentifiable.</param>
49-
List<AttrAttribute> GetAttributes(Type type);
50-
/// <summary>
51-
/// Gets all exposed relationships for type <paramref name="type"/>
52-
/// </summary>
53-
/// <param name="type">The resource type. Must extend IIdentifiable.</param>
54-
List<RelationshipAttribute> GetRelationships(Type type);
55-
56-
/// <summary>
57-
/// Traverses the resource graph for the inverse relationship of the provided
58-
/// <paramref name="relationship"/>;
59-
/// </summary>
60-
/// <param name="relationship"></param>
61-
RelationshipAttribute GetInverse(RelationshipAttribute relationship);
62-
}
63-
649
/// <summary>
6510
/// Responsible for getting <see cref="ContextEntity"/>s from the <see cref="ResourceGraph"/>.
6611
/// </summary>

src/JsonApiDotNetCore/Internal/Contracts/IResourceGraphExplorer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace JsonApiDotNetCore.Internal.Contracts
77
{
88
/// <summary>
99
/// Responsible for retrieving the exposed resource fields (attributes and
10-
/// relationships) of registered resources in the resource graph.
10+
/// relationships) of registered resources in the resource resourceGraph.
1111
/// </summary>
12-
public interface IResourceGraphExplorer : IContextEntityProvider
12+
public interface IResourceGraph : IContextEntityProvider
1313
{
1414
/// <summary>
1515
/// Gets all fields (attributes and relationships) for <typeparamref name="TResource"/>
@@ -52,7 +52,7 @@ public interface IResourceGraphExplorer : IContextEntityProvider
5252
List<RelationshipAttribute> GetRelationships(Type type);
5353

5454
/// <summary>
55-
/// Traverses the resource graph for the inverse relationship of the provided
55+
/// Traverses the resource resourceGraph for the inverse relationship of the provided
5656
/// <paramref name="relationship"/>;
5757
/// </summary>
5858
/// <param name="relationship"></param>

0 commit comments

Comments
 (0)