Skip to content

Commit 0708c1c

Browse files
committed
fix: IRelationshipDictionary implements IReadOnlyDictionary
1 parent 8cca15a commit 0708c1c

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

src/JsonApiDotNetCore/Hooks/Execution/EntityDiffs.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace JsonApiDotNetCore.Hooks
1414
/// Also contains information about updated relationships through
1515
/// implementation of IRelationshipsDictionary<typeparamref name="TEntity"/>>
1616
/// </summary>
17-
public interface IEntityDiff<TEntity> : IRelationshipsDictionary<TEntity>, IEnumerable<EntityDiffPair<TEntity>> where TEntity : class, IIdentifiable
17+
public interface IEntityDiff<TEntity> : IExposeRelationshipsDictionary<TEntity>, IEnumerable<EntityDiffPair<TEntity>> where TEntity : class, IIdentifiable
1818
{
1919
/// <summary>
2020
/// The database values of the resources affected by the request.
@@ -42,7 +42,7 @@ public class EntityDiffs<TEntity> : IEntityDiff<TEntity> where TEntity : class,
4242

4343
public EntityDiffs(HashSet<TEntity> requestEntities,
4444
HashSet<TEntity> databaseEntities,
45-
Dictionary<RelationshipAttribute, HashSet<TEntity>> relationships)
45+
Dictionary<RelationshipAttribute, HashSet<TEntity>> relationships)
4646
{
4747
Entities = requestEntities;
4848
AffectedRelationships = new RelationshipsDictionary<TEntity>(relationships);
@@ -55,7 +55,7 @@ public EntityDiffs(HashSet<TEntity> requestEntities,
5555
/// </summary>
5656
internal EntityDiffs(IEnumerable requestEntities,
5757
IEnumerable databaseEntities,
58-
Dictionary<RelationshipAttribute, IEnumerable> relationships)
58+
Dictionary<RelationshipAttribute, IEnumerable> relationships)
5959
: this((HashSet<TEntity>)requestEntities, (HashSet<TEntity>)databaseEntities, TypeHelper.ConvertRelationshipDictionary<TEntity>(relationships)) { }
6060

6161

src/JsonApiDotNetCore/Hooks/Execution/EntityHashSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace JsonApiDotNetCore.Hooks
1212
/// Also contains information about updated relationships through
1313
/// implementation of IAffectedRelationshipsDictionary<typeparamref name="TResource"/>>
1414
/// </summary>
15-
public interface IEntityHashSet<TResource> : IRelationshipsDictionary<TResource>, IEnumerable<TResource> where TResource : class, IIdentifiable { }
15+
public interface IEntityHashSet<TResource> : IExposeRelationshipsDictionary<TResource>, IEnumerable<TResource> where TResource : class, IIdentifiable { }
1616

1717
/// <summary>
1818
/// Implementation of IResourceHashSet{TResource}.

src/JsonApiDotNetCore/Hooks/Execution/RelationshipsDictionary.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public interface IRelationshipsDictionary { }
1313
/// <summary>
1414
/// An interface that is implemented to expose a relationship dictionary on another class.
1515
/// </summary>
16-
public interface IExposeRelationshipsDictionary<TDependentResource> : IRelationshipsDictionary<TDependentResource> where TDependentResource : class, IIdentifiable
16+
public interface IExposeRelationshipsDictionary<TDependentResource> :
17+
IRelationshipsDictionaryGetters<TDependentResource> where TDependentResource : class, IIdentifiable
1718
{
1819
/// <summary>
1920
/// Gets a dictionary of affected resources grouped by affected relationships.
@@ -24,7 +25,15 @@ public interface IExposeRelationshipsDictionary<TDependentResource> : IRelations
2425
/// <summary>
2526
/// A helper class that provides insights in which relationships have been updated for which entities.
2627
/// </summary>
27-
public interface IRelationshipsDictionary<TDependentResource> : IRelationshipsDictionary where TDependentResource : class, IIdentifiable
28+
public interface IRelationshipsDictionary<TDependentResource> :
29+
IRelationshipsDictionaryGetters<TDependentResource>,
30+
IReadOnlyDictionary<RelationshipAttribute, HashSet<TDependentResource>>,
31+
IRelationshipsDictionary where TDependentResource : class, IIdentifiable { }
32+
33+
/// <summary>
34+
/// A helper class that provides insights in which relationships have been updated for which entities.
35+
/// </summary>
36+
public interface IRelationshipsDictionaryGetters<TDependentResource> where TDependentResource : class, IIdentifiable
2837
{
2938
/// <summary>
3039
/// Gets a dictionary of all entities that have an affected relationship to type <typeparamref name="TPrincipalResource"/>
@@ -42,7 +51,9 @@ public interface IRelationshipsDictionary<TDependentResource> : IRelationshipsDi
4251
/// It is practically a ReadOnlyDictionary{RelationshipAttribute, HashSet{TDependentResource}} dictionary
4352
/// with the two helper methods defined on IAffectedRelationships{TDependentResource}.
4453
/// </summary>
45-
public class RelationshipsDictionary<TDependentResource> : ReadOnlyDictionary<RelationshipAttribute, HashSet<TDependentResource>>, IRelationshipsDictionary<TDependentResource> where TDependentResource : class, IIdentifiable
54+
public class RelationshipsDictionary<TDependentResource> :
55+
ReadOnlyDictionary<RelationshipAttribute, HashSet<TDependentResource>>,
56+
IRelationshipsDictionary<TDependentResource> where TDependentResource : class, IIdentifiable
4657
{
4758
/// <summary>
4859
/// a dictionary with affected relationships as keys and values being the corresponding resources
@@ -62,7 +73,6 @@ public RelationshipsDictionary(Dictionary<RelationshipAttribute, HashSet<TDepend
6273
internal RelationshipsDictionary(Dictionary<RelationshipAttribute, IEnumerable> relationships)
6374
: this(TypeHelper.ConvertRelationshipDictionary<TDependentResource>(relationships)) { }
6475

65-
6676
/// <inheritdoc />
6777
public Dictionary<RelationshipAttribute, HashSet<TDependentResource>> GetByRelationship<TPrincipalResource>() where TPrincipalResource : class, IIdentifiable
6878
{

src/JsonApiDotNetCore/Hooks/ResourceHookExecutor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ void ValidateHookResponse<T>(IEnumerable<T> returnedList, ResourcePipeline pipel
318318
PrincipalType principalType = dependentEntities.First().Key.PrincipalType;
319319
var byInverseRelationship = dependentEntities.Where(kvp => kvp.Key.InverseNavigation != null).ToDictionary(kvp => GetInverseRelationship(kvp.Key), kvp => kvp.Value);
320320
return (byInverseRelationship, principalType);
321-
322321
}
323322

324323
/// <summary>

src/JsonApiDotNetCore/Models/ResourceDefinition.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,19 @@ public virtual void AfterUpdate(HashSet<T> entities, ResourcePipeline pipeline)
173173
/// <inheritdoc/>
174174
public virtual void AfterDelete(HashSet<T> entities, ResourcePipeline pipeline, bool succeeded) { }
175175
/// <inheritdoc/>
176-
public virtual void AfterUpdateRelationship(IRelationshipsDictionary<T> resourcesByRelationship, ResourcePipeline pipeline) { }
176+
public virtual void AfterUpdateRelationship(IRelationshipsDictionary<T> entitiesByRelationship, ResourcePipeline pipeline) { }
177177
/// <inheritdoc/>
178-
public virtual IEnumerable<T> BeforeCreate(IEntityHashSet<T> affected, ResourcePipeline pipeline) { return affected; }
178+
public virtual IEnumerable<T> BeforeCreate(IEntityHashSet<T> entities, ResourcePipeline pipeline) { return entities; }
179179
/// <inheritdoc/>
180180
public virtual void BeforeRead(ResourcePipeline pipeline, bool isIncluded = false, string stringId = null) { }
181181
/// <inheritdoc/>
182-
public virtual IEnumerable<T> BeforeUpdate(IEntityDiff<T> ResourceDiff, ResourcePipeline pipeline) { return ResourceDiff.Entities; }
182+
public virtual IEnumerable<T> BeforeUpdate(IEntityDiff<T> entityDiff, ResourcePipeline pipeline) { return entityDiff.Entities; }
183183
/// <inheritdoc/>
184-
public virtual IEnumerable<T> BeforeDelete(IEntityHashSet<T> affected, ResourcePipeline pipeline) { return affected; }
184+
public virtual IEnumerable<T> BeforeDelete(IEntityHashSet<T> entities, ResourcePipeline pipeline) { return entities; }
185185
/// <inheritdoc/>
186-
public virtual IEnumerable<string> BeforeUpdateRelationship(HashSet<string> ids, IRelationshipsDictionary<T> resourcesByRelationship, ResourcePipeline pipeline) { return ids; }
186+
public virtual IEnumerable<string> BeforeUpdateRelationship(HashSet<string> ids, IRelationshipsDictionary<T> entitiesByRelationship, ResourcePipeline pipeline) { return ids; }
187187
/// <inheritdoc/>
188-
public virtual void BeforeImplicitUpdateRelationship(IRelationshipsDictionary<T> resourcesByRelationship, ResourcePipeline pipeline) { }
188+
public virtual void BeforeImplicitUpdateRelationship(IRelationshipsDictionary<T> entitiesByRelationship, ResourcePipeline pipeline) { }
189189
/// <inheritdoc/>
190190
public virtual IEnumerable<T> OnReturn(HashSet<T> entities, ResourcePipeline pipeline) { return entities; }
191191

0 commit comments

Comments
 (0)