Skip to content

Commit b5a27c4

Browse files
committed
refactor: renamed some internals, and added id to mapped out entity in service layer
1 parent 1ecab38 commit b5a27c4

File tree

8 files changed

+15
-11
lines changed

8 files changed

+15
-11
lines changed

src/Examples/JsonApiDotNetCoreExample/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public virtual IServiceProvider ConfigureServices(IServiceCollection services)
4040
options.DefaultPageSize = 5;
4141
options.IncludeTotalRecordCount = true;
4242
options.EnableResourceHooks = true;
43-
options.DatabaseValuesInDiffs = true;
43+
options.LoadDatabaseValues = true;
4444
},
4545
mvcBuilder,
4646
discovery => discovery.AddCurrentAssembly());

src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class JsonApiOptions
5050
///
5151
/// Defaults to <see langword="true"/>.
5252
/// </summary>
53-
public bool DatabaseValuesInDiffs { get; set; } = true;
53+
public bool LoadDatabaseValues { get; set; } = true;
5454

5555
/// <summary>
5656
/// The base URL Namespace

src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ public static IApplicationBuilder UseJsonApi(this IApplicationBuilder app, bool
2222
if (useMvc)
2323
app.UseMvc();
2424

25-
var inverseRelationshipResolver = app.ApplicationServices.GetService<IInverseRelationships>();
26-
inverseRelationshipResolver?.Resolve();
25+
using (var scope = app.ApplicationServices.CreateScope())
26+
{
27+
var inverseRelationshipResolver = scope.ServiceProvider.GetService<IInverseRelationships>();
28+
inverseRelationshipResolver?.Resolve();
29+
}
2730

2831
return app;
2932
}

src/JsonApiDotNetCore/Hooks/Discovery/HooksDiscovery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void DiscoverImplementedHooksForModel()
5656
diffEnabledHooks.Add(hook);
5757
continue;
5858
}
59-
var attr = method.GetCustomAttributes(true).OfType<IncludeDatabaseValues>().SingleOrDefault();
59+
var attr = method.GetCustomAttributes(true).OfType<LoadDatabaseValues>().SingleOrDefault();
6060
if (attr != null)
6161
{
6262
var targetList = attr.value ? diffEnabledHooks : diffDisabledHooks;

src/JsonApiDotNetCore/Hooks/Discovery/IncludeDatabaseValues.cs renamed to src/JsonApiDotNetCore/Hooks/Discovery/LoadDatabaseValuesAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System;
22
namespace JsonApiDotNetCore.Hooks
33
{
4-
public class IncludeDatabaseValues : Attribute
4+
public class LoadDatabaseValues : Attribute
55
{
66
public readonly bool value;
7-
public IncludeDatabaseValues(bool mode = true)
7+
public LoadDatabaseValues(bool mode = true)
88
{
99
value = mode;
1010
}

src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ bool ShouldLoadDbValues(DependentType entityType, ResourceHook hook)
118118
}
119119
else
120120
{
121-
return _context.Options.DatabaseValuesInDiffs;
121+
return _context.Options.LoadDatabaseValues;
122122
}
123123

124124
}

src/JsonApiDotNetCore/Services/EntityResourceService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,14 @@ public virtual async Task<object> GetRelationshipAsync(TId id, string relationsh
215215
public virtual async Task<TResource> UpdateAsync(TId id, TResource resource)
216216
{
217217
var entity = MapIn(resource);
218-
218+
// why is entity passed along to UpdateAsync if it is never used internally??
219+
// I think we should just set the id on the request-parsed entity and pass that along to the repo.
220+
entity.Id = id;
219221

220222
entity = IsNull(_hookExecutor) ? entity : _hookExecutor.BeforeUpdate(AsList(entity), ResourcePipeline.Patch).SingleOrDefault();
221223
entity = await _entities.UpdateAsync(id, entity);
222224
if (!IsNull(_hookExecutor, entity))
223225
{
224-
// TODO: should not fire after read for L=0
225226
_hookExecutor.AfterUpdate(AsList(entity), ResourcePipeline.Patch);
226227
entity = _hookExecutor.OnReturn(AsList(entity), ResourcePipeline.Patch).SingleOrDefault();
227228
}

test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void MockHooks<TModel>(Mock<IResourceHookContainer<TModel>> resourceDefinition)
302302
var processorFactory = new Mock<IGenericProcessorFactory>();
303303
var context = new Mock<IJsonApiContext>();
304304
context.Setup(c => c.GenericProcessorFactory).Returns(processorFactory.Object);
305-
context.Setup(c => c.Options).Returns(new JsonApiOptions { DatabaseValuesInDiffs = false });
305+
context.Setup(c => c.Options).Returns(new JsonApiOptions { LoadDatabaseValues = false });
306306
context.Setup(c => c.ResourceGraph).Returns(ResourceGraph.Instance);
307307

308308
return (context, processorFactory);

0 commit comments

Comments
 (0)