Skip to content

Commit d038582

Browse files
committed
style: ContextEntity --> ResourceContext
1 parent 519513d commit d038582

Some content is hidden

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

43 files changed

+131
-131
lines changed

benchmarks/Query/QueryParser_Benchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class QueryParser_Benchmarks {
2323

2424
public QueryParser_Benchmarks() {
2525
var requestMock = new Mock<IRequestContext>();
26-
requestMock.Setup(m => m.GetRequestResource()).Returns(new ContextEntity {
26+
requestMock.Setup(m => m.GetRequestResource()).Returns(new ResourceContext {
2727
Attributes = new List<AttrAttribute> {
2828
new AttrAttribute(ATTRIBUTE, ATTRIBUTE)
2929
}

src/Examples/GettingStarted/ResourceDefinitionExample/ModelDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace GettingStarted.ResourceDefinitionExample
66
{
77
public class ModelDefinition : ResourceDefinition<Model>
88
{
9-
public ModelDefinition(IContextEntityProvider provider) : base(provider)
9+
public ModelDefinition(IResourceContextProvider provider) : base(provider)
1010
{
1111
}
1212

src/Examples/JsonApiDotNetCoreExample/Services/CustomArticleService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public CustomArticleService(ISortService sortService,
2020
IIncludeService includeService,
2121
ISparseFieldsService sparseFieldsService,
2222
IPageService pageService,
23-
IContextEntityProvider provider,
23+
IResourceContextProvider provider,
2424
IResourceHookExecutor hookExecutor = null,
2525
ILoggerFactory loggerFactory = null)
2626
: base(sortService, filterService, repository, options, includeService, sparseFieldsService,

src/JsonApiDotNetCore/Builders/JsonApiApplicationBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void ConfigureServices()
149149
_services.AddSingleton(resourceGraph);
150150
_services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
151151
_services.AddSingleton<IResourceGraph>(resourceGraph);
152-
_services.AddSingleton<IContextEntityProvider>(resourceGraph);
152+
_services.AddSingleton<IResourceContextProvider>(resourceGraph);
153153
_services.AddScoped<ICurrentRequest, CurrentRequest>();
154154
_services.AddScoped<IScopedServiceProvider, RequestScopedServiceProvider>();
155155
_services.AddScoped<IJsonApiWriter, JsonApiWriter>();

src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace JsonApiDotNetCore.Builders
1717
{
1818
public class ResourceGraphBuilder : IResourceGraphBuilder
1919
{
20-
private readonly List<ContextEntity> _entities = new List<ContextEntity>();
20+
private readonly List<ResourceContext> _entities = new List<ResourceContext>();
2121
private readonly List<ValidationResult> _validationResults = new List<ValidationResult>();
2222
private readonly IResourceNameFormatter _resourceNameFormatter = new KebabCaseFormatter();
2323

@@ -36,7 +36,7 @@ public IResourceGraph Build()
3636
return resourceGraph;
3737
}
3838

39-
private void SetResourceLinksOptions(ContextEntity resourceContext)
39+
private void SetResourceLinksOptions(ResourceContext resourceContext)
4040
{
4141
var attribute = (LinksAttribute)resourceContext.EntityType.GetCustomAttribute(typeof(LinksAttribute));
4242
if (attribute != null)
@@ -67,7 +67,7 @@ public IResourceGraphBuilder AddResource(Type entityType, Type idType, string pl
6767
return this;
6868
}
6969

70-
private ContextEntity GetEntity(string pluralizedTypeName, Type entityType, Type idType) => new ContextEntity
70+
private ResourceContext GetEntity(string pluralizedTypeName, Type entityType, Type idType) => new ResourceContext
7171
{
7272
EntityName = pluralizedTypeName,
7373
EntityType = entityType,

src/JsonApiDotNetCore/Internal/ContextEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace JsonApiDotNetCore.Internal
88
{
9-
public class ContextEntity
9+
public class ResourceContext
1010
{
1111
/// <summary>
1212
/// The exposed resource name

src/JsonApiDotNetCore/Internal/Contracts/IContextEntityProvider.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@
77
namespace JsonApiDotNetCore.Internal.Contracts
88
{
99
/// <summary>
10-
/// Responsible for getting <see cref="ContextEntity"/>s from the <see cref="ResourceGraph"/>.
10+
/// Responsible for getting <see cref="ResourceContext"/>s from the <see cref="ResourceGraph"/>.
1111
/// </summary>
12-
public interface IContextEntityProvider
12+
public interface IResourceContextProvider
1313
{
1414
/// <summary>
1515
/// Gets all registered context entities
1616
/// </summary>
17-
ContextEntity[] GetContextEntities();
17+
ResourceContext[] GetContextEntities();
1818

1919
/// <summary>
2020
/// Get the resource metadata by the DbSet property name
2121
/// </summary>
22-
ContextEntity GetContextEntity(string exposedResourceName);
22+
ResourceContext GetResourceContext(string exposedResourceName);
2323

2424
/// <summary>
2525
/// Get the resource metadata by the resource type
2626
/// </summary>
27-
ContextEntity GetContextEntity(Type resourceType);
27+
ResourceContext GetResourceContext(Type resourceType);
2828

2929
/// <summary>
3030
/// Get the resource metadata by the resource type
3131
/// </summary>
32-
ContextEntity GetContextEntity<TResource>() where TResource : class, IIdentifiable;
32+
ResourceContext GetResourceContext<TResource>() where TResource : class, IIdentifiable;
3333
}
3434
}

src/JsonApiDotNetCore/Internal/Contracts/IResourceGraphExplorer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace JsonApiDotNetCore.Internal.Contracts
99
/// Responsible for retrieving the exposed resource fields (attributes and
1010
/// relationships) of registered resources in the resource resourceGraph.
1111
/// </summary>
12-
public interface IResourceGraph : IContextEntityProvider
12+
public interface IResourceGraph : IResourceContextProvider
1313
{
1414
/// <summary>
1515
/// Gets all fields (attributes and relationships) for <typeparamref name="TResource"/>

src/JsonApiDotNetCore/Internal/InverseRelationships.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public interface IInverseRelationships
2929
/// <inheritdoc />
3030
public class InverseRelationships : IInverseRelationships
3131
{
32-
private readonly IContextEntityProvider _provider;
32+
private readonly IResourceContextProvider _provider;
3333
private readonly IDbContextResolver _resolver;
3434

35-
public InverseRelationships(IContextEntityProvider provider, IDbContextResolver resolver = null)
35+
public InverseRelationships(IResourceContextProvider provider, IDbContextResolver resolver = null)
3636
{
3737
_provider = provider;
3838
_resolver = resolver;
@@ -45,7 +45,7 @@ public void Resolve()
4545
{
4646
DbContext context = _resolver.GetContext();
4747

48-
foreach (ContextEntity ce in _provider.GetContextEntities())
48+
foreach (ResourceContext ce in _provider.GetContextEntities())
4949
{
5050
IEntityType meta = context.Model.FindEntityType(ce.EntityType);
5151
if (meta == null) continue;

src/JsonApiDotNetCore/Internal/ResourceGraph.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ namespace JsonApiDotNetCore.Internal
1313
public class ResourceGraph : IResourceGraph
1414
{
1515
internal List<ValidationResult> ValidationResults { get; }
16-
private List<ContextEntity> _entities { get; }
16+
private List<ResourceContext> _entities { get; }
1717

18-
public ResourceGraph(List<ContextEntity> entities, List<ValidationResult> validationResults = null)
18+
public ResourceGraph(List<ResourceContext> entities, List<ValidationResult> validationResults = null)
1919
{
2020
_entities = entities;
2121
ValidationResults = validationResults;
2222
}
2323

2424
/// <inheritdoc />
25-
public ContextEntity[] GetContextEntities() => _entities.ToArray();
25+
public ResourceContext[] GetContextEntities() => _entities.ToArray();
2626

2727
/// <inheritdoc />
28-
public ContextEntity GetContextEntity(string entityName)
28+
public ResourceContext GetResourceContext(string entityName)
2929
=> _entities.SingleOrDefault(e => string.Equals(e.EntityName, entityName, StringComparison.OrdinalIgnoreCase));
3030

3131
/// <inheritdoc />
32-
public ContextEntity GetContextEntity(Type entityType)
32+
public ResourceContext GetResourceContext(Type entityType)
3333
=> _entities.SingleOrDefault(e => e.EntityType == entityType);
3434
/// <inheritdoc />
35-
public ContextEntity GetContextEntity<TResource>() where TResource : class, IIdentifiable
36-
=> GetContextEntity(typeof(TResource));
35+
public ResourceContext GetResourceContext<TResource>() where TResource : class, IIdentifiable
36+
=> GetResourceContext(typeof(TResource));
3737

3838
/// <inheritdoc/>
3939
public List<IResourceField> GetFields<T>(Expression<Func<T, dynamic>> selector = null) where T : IIdentifiable
@@ -53,24 +53,24 @@ public List<RelationshipAttribute> GetRelationships<T>(Expression<Func<T, dynami
5353
/// <inheritdoc/>
5454
public List<IResourceField> GetFields(Type type)
5555
{
56-
return GetContextEntity(type).Fields.ToList();
56+
return GetResourceContext(type).Fields.ToList();
5757
}
5858
/// <inheritdoc/>
5959
public List<AttrAttribute> GetAttributes(Type type)
6060
{
61-
return GetContextEntity(type).Attributes.ToList();
61+
return GetResourceContext(type).Attributes.ToList();
6262
}
6363
/// <inheritdoc/>
6464
public List<RelationshipAttribute> GetRelationships(Type type)
6565
{
66-
return GetContextEntity(type).Relationships.ToList();
66+
return GetResourceContext(type).Relationships.ToList();
6767
}
6868

6969
/// <inheritdoc />
7070
public RelationshipAttribute GetInverse(RelationshipAttribute relationship)
7171
{
7272
if (relationship.InverseNavigation == null) return null;
73-
return GetContextEntity(relationship.DependentType)
73+
return GetResourceContext(relationship.DependentType)
7474
.Relationships
7575
.SingleOrDefault(r => r.InternalRelationshipName == relationship.InverseNavigation);
7676
}
@@ -79,11 +79,11 @@ private IEnumerable<IResourceField> Getter<T>(Expression<Func<T, dynamic>> selec
7979
{
8080
IEnumerable<IResourceField> available;
8181
if (type == FieldFilterType.Attribute)
82-
available = GetContextEntity(typeof(T)).Attributes.Cast<IResourceField>();
82+
available = GetResourceContext(typeof(T)).Attributes.Cast<IResourceField>();
8383
else if (type == FieldFilterType.Relationship)
84-
available = GetContextEntity(typeof(T)).Relationships.Cast<IResourceField>();
84+
available = GetResourceContext(typeof(T)).Relationships.Cast<IResourceField>();
8585
else
86-
available = GetContextEntity(typeof(T)).Fields;
86+
available = GetResourceContext(typeof(T)).Fields;
8787

8888
if (selector == null)
8989
return available;

src/JsonApiDotNetCore/Middleware/DefaultTypeMatchFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace JsonApiDotNetCore.Middleware
1212
/// </summary>
1313
public class DefaultTypeMatchFilter : IActionFilter
1414
{
15-
private readonly IContextEntityProvider _provider;
15+
private readonly IResourceContextProvider _provider;
1616

17-
public DefaultTypeMatchFilter(IContextEntityProvider provider)
17+
public DefaultTypeMatchFilter(IResourceContextProvider provider)
1818
{
1919
_provider = provider;
2020
}
@@ -29,7 +29,7 @@ public void OnActionExecuting(ActionExecutingContext context)
2929

3030
if (deserializedType != null && targetType != null && deserializedType != targetType)
3131
{
32-
var expectedJsonApiResource = _provider.GetContextEntity(targetType);
32+
var expectedJsonApiResource = _provider.GetResourceContext(targetType);
3333

3434
throw new JsonApiException(409,
3535
$"Cannot '{context.HttpContext.Request.Method}' type '{deserializedType.Name}' "

src/JsonApiDotNetCore/Middleware/RequestMiddleware.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ private void FlushResponse(HttpContext context, int statusCode)
163163
/// Gets the current entity that we need for serialization and deserialization.
164164
/// </summary>
165165
/// <returns></returns>
166-
private ContextEntity GetCurrentEntity()
166+
private ResourceContext GetCurrentEntity()
167167
{
168168
var controllerName = (string)_httpContext.GetRouteData().Values["controller"];
169169
var resourceType = _controllerResourceMapping.GetAssociatedResource(controllerName);
170-
var requestResource = _resourceGraph.GetContextEntity(resourceType);
170+
var requestResource = _resourceGraph.GetResourceContext(resourceType);
171171
if (requestResource == null)
172172
return requestResource;
173173
var rd = _httpContext.GetRouteData().Values;

src/JsonApiDotNetCore/Models/Annotation/HasOneAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class HasOneAttribute : RelationshipAttribute
1212
///
1313
/// <param name="publicName">The relationship name as exposed by the API</param>
1414
/// <param name="links">Enum to set which links should be outputted for this relationship. Defaults to <see cref="Link.NotConfigured"/> which means that the configuration in
15-
/// <see cref="ILinksConfiguration"/> or <see cref="ContextEntity"/> is used.</param>
15+
/// <see cref="ILinksConfiguration"/> or <see cref="ResourceContext"/> is used.</param>
1616
/// <param name="canInclude">Whether or not this relationship can be included using the <c>?include=public-name</c> query string</param>
1717
/// <param name="withForeignKey">The foreign key property name. Defaults to <c>"{RelationshipName}Id"</c></param>
1818
/// <param name="mappedBy">The name of the entity mapped property, defaults to null</param>

src/JsonApiDotNetCore/Models/ResourceDefinition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public interface IResourceDefinition
2828
/// <typeparam name="TResource">The resource type</typeparam>
2929
public class ResourceDefinition<TResource> : IResourceDefinition, IResourceHookContainer<TResource> where TResource : class, IIdentifiable
3030
{
31-
private readonly ContextEntity _contextEntity;
31+
private readonly ResourceContext _contextEntity;
3232
private readonly IResourceGraph _resourceGraph;
3333
private List<AttrAttribute> _allowedAttributes;
3434
private List<RelationshipAttribute> _allowedRelationships;
3535
public ResourceDefinition(IResourceGraph resourceGraph)
3636
{
37-
_contextEntity = resourceGraph.GetContextEntity(typeof(TResource));
37+
_contextEntity = resourceGraph.GetResourceContext(typeof(TResource));
3838
_allowedAttributes = _contextEntity.Attributes;
3939
_allowedRelationships = _contextEntity.Relationships;
4040
_resourceGraph = resourceGraph;

src/JsonApiDotNetCore/QueryParameterServices/Common/QueryParameterService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace JsonApiDotNetCore.Query
1515
public abstract class QueryParameterService
1616
{
1717
protected readonly IResourceGraph _resourceGraph;
18-
protected readonly ContextEntity _requestResource;
18+
protected readonly ResourceContext _requestResource;
1919

2020
protected QueryParameterService(IResourceGraph resourceGraph, ICurrentRequest currentRequest)
2121
{

src/JsonApiDotNetCore/QueryParameterServices/IncludeService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ private void ParseChain(string chain)
5252
throw CannotIncludeError(resourceContext, relationshipName);
5353

5454
parsedChain.Add(relationship);
55-
resourceContext = _resourceGraph.GetContextEntity(relationship.DependentType);
55+
resourceContext = _resourceGraph.GetResourceContext(relationship.DependentType);
5656
}
5757
_includedChains.Add(parsedChain);
5858
}
5959

60-
private JsonApiException CannotIncludeError(ContextEntity resourceContext, string requestedRelationship)
60+
private JsonApiException CannotIncludeError(ResourceContext resourceContext, string requestedRelationship)
6161
{
6262
return new JsonApiException(400, $"Including the relationship {requestedRelationship} on {resourceContext.EntityName} is not allowed");
6363
}
6464

65-
private JsonApiException InvalidRelationshipError(ContextEntity resourceContext, string requestedRelationship)
65+
private JsonApiException InvalidRelationshipError(ResourceContext resourceContext, string requestedRelationship)
6666
{
6767
return new JsonApiException(400, $"Invalid relationship {requestedRelationship} on {resourceContext.EntityName}",
6868
$"{resourceContext.EntityName} does not have a relationship named {requestedRelationship}");

src/JsonApiDotNetCore/QueryParameterServices/SparseFieldsService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public virtual void Parse(KeyValuePair<string, StringValues> queryParameter)
8383
/// </summary>
8484
private void RegisterRelatedResourceField(string field, RelationshipAttribute relationship)
8585
{
86-
var relationProperty = _resourceGraph.GetContextEntity(relationship.DependentType);
86+
var relationProperty = _resourceGraph.GetResourceContext(relationship.DependentType);
8787
var attr = relationProperty.Attributes.SingleOrDefault(a => a.Is(field));
8888
if (attr == null)
8989
throw new JsonApiException(400, $"'{relationship.DependentType.Name}' does not contain '{field}'.");

src/JsonApiDotNetCore/RequestServices/Contracts/ICurrentRequest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public interface ICurrentRequest
3636
/// Sets the current context entity for this entire request
3737
/// </summary>
3838
/// <param name="contextEntityCurrent"></param>
39-
void SetRequestResource(ContextEntity contextEntityCurrent);
39+
void SetRequestResource(ResourceContext contextEntityCurrent);
4040

41-
ContextEntity GetRequestResource();
41+
ResourceContext GetRequestResource();
4242
}
4343
}

src/JsonApiDotNetCore/RequestServices/CurrentRequest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace JsonApiDotNetCore.Managers
66
{
77
class CurrentRequest : ICurrentRequest
88
{
9-
private ContextEntity _contextEntity;
9+
private ResourceContext _contextEntity;
1010
public string BasePath { get; set; }
1111
public bool IsRelationshipPath { get; set; }
1212
public RelationshipAttribute RequestRelationship { get; set; }
@@ -15,12 +15,12 @@ class CurrentRequest : ICurrentRequest
1515
/// The main resource of the request.
1616
/// </summary>
1717
/// <returns></returns>
18-
public ContextEntity GetRequestResource()
18+
public ResourceContext GetRequestResource()
1919
{
2020
return _contextEntity;
2121
}
2222

23-
public void SetRequestResource(ContextEntity primaryResource)
23+
public void SetRequestResource(ResourceContext primaryResource)
2424
{
2525
_contextEntity = primaryResource;
2626
}

src/JsonApiDotNetCore/Serialization/Client/ResponseDeserializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace JsonApiDotNetCore.Serialization.Client
1313
/// </summary>
1414
public class ResponseDeserializer : BaseDocumentParser, IResponseDeserializer
1515
{
16-
public ResponseDeserializer(IContextEntityProvider provider) : base(provider) { }
16+
public ResponseDeserializer(IResourceContextProvider provider) : base(provider) { }
1717

1818
/// <inheritdoc/>
1919
public DeserializedSingleResponse<TResource> DeserializeSingle<TResource>(string body) where TResource : class, IIdentifiable
@@ -91,7 +91,7 @@ private IIdentifiable ParseIncludedRelationship(RelationshipAttribute relationsh
9191
if (includedResource == null)
9292
return relatedInstance;
9393

94-
var contextEntity = _provider.GetContextEntity(relatedResourceIdentifier.Type);
94+
var contextEntity = _provider.GetResourceContext(relatedResourceIdentifier.Type);
9595
if (contextEntity == null)
9696
throw new InvalidOperationException($"Included type '{relationshipAttr.DependentType}' is not a registered json:api resource.");
9797

src/JsonApiDotNetCore/Serialization/Common/BaseDocumentParser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ namespace JsonApiDotNetCore.Serialization
1818
/// </summary>
1919
public abstract class BaseDocumentParser
2020
{
21-
protected readonly IContextEntityProvider _provider;
21+
protected readonly IResourceContextProvider _provider;
2222
protected Document _document;
2323

24-
protected BaseDocumentParser(IContextEntityProvider provider)
24+
protected BaseDocumentParser(IResourceContextProvider provider)
2525
{
2626
_provider = provider;
2727
}
@@ -128,7 +128,7 @@ private JToken LoadJToken(string body)
128128
/// <returns>The parsed entity</returns>
129129
private IIdentifiable ParseResourceObject(ResourceObject data)
130130
{
131-
var contextEntity = _provider.GetContextEntity(data.Type);
131+
var contextEntity = _provider.GetResourceContext(data.Type);
132132
if (contextEntity == null)
133133
{
134134
throw new JsonApiException(400,

0 commit comments

Comments
 (0)