Skip to content

Commit c2d6417

Browse files
committed
style: consistent variable naming|
1 parent 1ad32fa commit c2d6417

12 files changed

+45
-57
lines changed

src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal class ResourceHookExecutor : IResourceHookExecutor
2121
private readonly ITraversalHelper _traversalHelper;
2222
private readonly IIncludeService _includeService;
2323
private readonly ITargetedFields _targetedFields;
24-
private readonly IResourceGraph _inverseRelationships;
24+
private readonly IResourceGraph _resourceGraph;
2525
public ResourceHookExecutor(
2626
IHookExecutorHelper executorHelper,
2727
ITraversalHelper traversalHelper,
@@ -33,7 +33,7 @@ public ResourceHookExecutor(
3333
_traversalHelper = traversalHelper;
3434
_targetedFields = targetedFields;
3535
_includeService = includedRelationships;
36-
_inverseRelationships = resourceGraph;
36+
_resourceGraph = resourceGraph;
3737
}
3838

3939
/// <inheritdoc/>
@@ -324,7 +324,7 @@ Dictionary<RelationshipAttribute, IEnumerable> ReplaceKeysWithInverseRelationshi
324324
/// If it isn't, JADNC currently knows nothing about this relationship pointing back, and it
325325
/// currently cannot fire hooks for entities resolved through inverse relationships.
326326
var inversableRelationshipAttributes = entitiesByRelationship.Where(kvp => kvp.Key.InverseNavigation != null);
327-
return inversableRelationshipAttributes.ToDictionary(kvp => _inverseRelationships.GetInverse(kvp.Key), kvp => kvp.Value);
327+
return inversableRelationshipAttributes.ToDictionary(kvp => _resourceGraph.GetInverse(kvp.Key), kvp => kvp.Value);
328328
}
329329

330330
/// <summary>
@@ -337,7 +337,7 @@ void FireForAffectedImplicits(Type entityTypeToInclude, Dictionary<RelationshipA
337337
if (container == null) return;
338338
var implicitAffected = _executorHelper.LoadImplicitlyAffected(implicitsTarget, existingImplicitEntities);
339339
if (!implicitAffected.Any()) return;
340-
var inverse = implicitAffected.ToDictionary(kvp => _inverseRelationships.GetInverse(kvp.Key), kvp => kvp.Value);
340+
var inverse = implicitAffected.ToDictionary(kvp => _resourceGraph.GetInverse(kvp.Key), kvp => kvp.Value);
341341
var resourcesByRelationship = CreateRelationshipHelper(entityTypeToInclude, inverse);
342342
CallHook(container, ResourceHook.BeforeImplicitUpdateRelationship, new object[] { resourcesByRelationship, pipeline, });
343343
}

src/JsonApiDotNetCore/Internal/DefaultRoutingConvention.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace JsonApiDotNetCore.Internal
3535
/// public class SomeVeryCustomController{SomeResource} : JsonApiMixin { }
3636
/// // => /some-very-customs/relationship/related-resource
3737
/// </example>
38-
public class DefaultRoutingConvention : IJsonApiRoutingConvention
38+
public class DefaultRoutingConvention : IJsonApiRoutingConvention, IControllerResourceMapping
3939
{
4040
private readonly string _namespace;
4141
private readonly IResourceNameFormatter _formatter;
@@ -120,11 +120,6 @@ private Type GetResourceTypeFromController(Type type)
120120
var target = typeof(BaseJsonApiController<,>);
121121
var identifiable = typeof(IIdentifiable);
122122
var currentBaseType = type;
123-
if (type.Name.Contains("TodoItemsCustom"))
124-
{
125-
var x = 123;
126-
}
127-
128123
while (!currentBaseType.IsGenericType || currentBaseType.GetGenericTypeDefinition() != target)
129124
{
130125
var nextBaseType = currentBaseType.BaseType;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace JsonApiDotNetCore.Internal
4+
{
5+
/// <summary>
6+
/// Registery of which resource is associated with which controller.
7+
/// </summary>
8+
public interface IControllerResourceMapping
9+
{
10+
/// <summary>
11+
/// Get the associated resource with the controller with the provided controller name
12+
/// </summary>
13+
Type GetAssociatedResource(string controllerName);
14+
}
15+
}

src/JsonApiDotNetCore/Internal/IDefaultRoutingConvention.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
using System;
2-
using Microsoft.AspNetCore.Mvc.ApplicationModels;
1+
using Microsoft.AspNetCore.Mvc.ApplicationModels;
32

43
namespace JsonApiDotNetCore.Internal
54
{
65
/// <summary>
76
/// Service for specifying which routing convention to use. This can be overriden to customize
87
/// the relation between controllers and mapped routes.
98
/// </summary>
10-
public interface IJsonApiRoutingConvention : IApplicationModelConvention
11-
{
12-
Type GetAssociatedResource(string controllerName);
13-
}
9+
public interface IJsonApiRoutingConvention : IApplicationModelConvention { }
1410
}

src/JsonApiDotNetCore/Middleware/RequestMiddleware.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ public class CurrentRequestMiddleware
2121
private readonly RequestDelegate _next;
2222
private HttpContext _httpContext;
2323
private ICurrentRequest _currentRequest;
24-
private IResourceGraph _contextEntityProvider;
24+
private IResourceGraph _resourceGraph;
2525
private IJsonApiOptions _options;
26-
private IJsonApiRoutingConvention _routingConvention;
26+
private IControllerResourceMapping _controllerResourceMapping;
2727

2828
public CurrentRequestMiddleware(RequestDelegate next)
2929
{
3030
_next = next;
3131
}
3232

3333
public async Task Invoke(HttpContext httpContext,
34-
IJsonApiRoutingConvention routingConvention,
35-
IJsonApiOptions options,
34+
IControllerResourceMapping controllerResourceMapping,
35+
IJsonApiOptions options,
3636
ICurrentRequest currentRequest,
37-
IResourceGraph contextEntityProvider)
37+
IResourceGraph resourceGraph)
3838
{
3939
_httpContext = httpContext;
4040
_currentRequest = currentRequest;
41-
_routingConvention = routingConvention;
42-
_contextEntityProvider = contextEntityProvider;
41+
_controllerResourceMapping = controllerResourceMapping;
42+
_resourceGraph = resourceGraph;
4343
_options = options;
4444
var requestResource = GetCurrentEntity();
4545
if (requestResource != null)
@@ -166,8 +166,8 @@ private void FlushResponse(HttpContext context, int statusCode)
166166
private ContextEntity GetCurrentEntity()
167167
{
168168
var controllerName = (string)_httpContext.GetRouteData().Values["controller"];
169-
var resourceType = _routingConvention.GetAssociatedResource(controllerName);
170-
var requestResource = _contextEntityProvider.GetContextEntity(resourceType);
169+
var resourceType = _controllerResourceMapping.GetAssociatedResource(controllerName);
170+
var requestResource = _resourceGraph.GetContextEntity(resourceType);
171171
if (requestResource == null)
172172
return requestResource;
173173
var rd = _httpContext.GetRouteData().Values;

src/JsonApiDotNetCore/Models/Annotation/HasManyThroughAttribute.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public override object GetValue(object entity)
103103
/// <param name="newValue">The new property value</param>
104104
public override void SetValue(object entity, object newValue)
105105
{
106-
107106
var propertyInfo = entity
108107
.GetType()
109108
.GetProperty(InternalRelationshipName);

src/JsonApiDotNetCore/QueryParameterServices/Common/QueryParameterService.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ namespace JsonApiDotNetCore.Query
1414
/// </summary>
1515
public abstract class QueryParameterService
1616
{
17-
protected readonly IResourceGraph _contextEntityProvider;
17+
protected readonly IResourceGraph _resourceGraph;
1818
protected readonly ContextEntity _requestResource;
1919

20-
protected QueryParameterService(IResourceGraph contextEntityProvider, ICurrentRequest currentRequest)
20+
protected QueryParameterService(IResourceGraph resourceGraph, ICurrentRequest currentRequest)
2121
{
22-
_contextEntityProvider = contextEntityProvider;
22+
_resourceGraph = resourceGraph;
2323
_requestResource = currentRequest.GetRequestResource();
2424
}
2525

@@ -48,15 +48,9 @@ protected AttrAttribute GetAttribute(string target, RelationshipAttribute relati
4848
{
4949
AttrAttribute attribute;
5050
if (relationship != null)
51-
{
52-
var relatedContextEntity = _contextEntityProvider.GetContextEntity(relationship.DependentType);
53-
attribute = relatedContextEntity.Attributes
54-
.FirstOrDefault(a => a.Is(target));
55-
}
51+
attribute = _resourceGraph.GetAttributes(relationship.DependentType).FirstOrDefault(a => a.Is(target));
5652
else
57-
{
5853
attribute = _requestResource.Attributes.FirstOrDefault(attr => attr.Is(target));
59-
}
6054

6155
if (attribute == null)
6256
throw new JsonApiException(400, $"'{target}' is not a valid attribute.");

src/JsonApiDotNetCore/QueryParameterServices/FilterService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class FilterService : QueryParameterService, IFilterService
1616
private readonly List<FilterQueryContext> _filters;
1717
private IResourceDefinition _requestResourceDefinition;
1818

19-
public FilterService(IResourceDefinitionProvider resourceDefinitionProvider, IResourceGraph contextEntityProvider, ICurrentRequest currentRequest) : base(contextEntityProvider, currentRequest)
19+
public FilterService(IResourceDefinitionProvider resourceDefinitionProvider, IResourceGraph resourceGraph, ICurrentRequest currentRequest) : base(resourceGraph, currentRequest)
2020
{
2121
_requestResourceDefinition = resourceDefinitionProvider.Get(_requestResource.EntityType);
2222
_filters = new List<FilterQueryContext>();

src/JsonApiDotNetCore/QueryParameterServices/IncludeService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class IncludeService : QueryParameterService, IIncludeService
1414
/// todo: use read-only lists.
1515
private readonly List<List<RelationshipAttribute>> _includedChains;
1616

17-
public IncludeService(IResourceGraph contextEntityProvider, ICurrentRequest currentRequest) : base(contextEntityProvider, currentRequest)
17+
public IncludeService(IResourceGraph resourceGraph, ICurrentRequest currentRequest) : base(resourceGraph, currentRequest)
1818
{
1919
_includedChains = new List<List<RelationshipAttribute>>();
2020
}
@@ -52,7 +52,7 @@ private void ParseChain(string chain)
5252
throw CannotIncludeError(resourceContext, relationshipName);
5353

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

0 commit comments

Comments
 (0)