Skip to content

Commit 8870ccd

Browse files
author
Bart Koelman
committed
Removed single-parameter resource repositories
1 parent 92bc642 commit 8870ccd

18 files changed

+17
-96
lines changed

src/Examples/MultiDbContextExample/Repositories/DbContextARepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace MultiDbContextExample.Repositories
1111
{
1212
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
13-
public sealed class DbContextARepository<TResource> : EntityFrameworkCoreRepository<TResource>
13+
public sealed class DbContextARepository<TResource> : EntityFrameworkCoreRepository<TResource, int>
1414
where TResource : class, IIdentifiable<int>
1515
{
1616
public DbContextARepository(ITargetedFields targetedFields, DbContextResolver<DbContextA> dbContextResolver, IResourceGraph resourceGraph,

src/Examples/MultiDbContextExample/Repositories/DbContextBRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace MultiDbContextExample.Repositories
1111
{
1212
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
13-
public sealed class DbContextBRepository<TResource> : EntityFrameworkCoreRepository<TResource>
13+
public sealed class DbContextBRepository<TResource> : EntityFrameworkCoreRepository<TResource, int>
1414
where TResource : class, IIdentifiable<int>
1515
{
1616
public DbContextBRepository(ITargetedFields targetedFields, DbContextResolver<DbContextB> dbContextResolver, IResourceGraph resourceGraph,

src/JsonApiDotNetCore/Configuration/JsonApiApplicationBuilder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ private void AddResourceLayer()
190190

191191
private void AddRepositoryLayer()
192192
{
193-
RegisterImplementationForOpenInterfaces(ServiceDiscoveryFacade.RepositoryInterfaces, typeof(EntityFrameworkCoreRepository<>),
194-
typeof(EntityFrameworkCoreRepository<,>));
193+
RegisterImplementationForOpenInterfaces(ServiceDiscoveryFacade.RepositoryInterfaces, null, typeof(EntityFrameworkCoreRepository<,>));
195194

196195
_services.AddScoped<IResourceRepositoryAccessor, ResourceRepositoryAccessor>();
197196
}

src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ public sealed class ServiceDiscoveryFacade
3636

3737
internal static readonly HashSet<Type> RepositoryInterfaces = new()
3838
{
39-
typeof(IResourceRepository<>),
4039
typeof(IResourceRepository<,>),
41-
typeof(IResourceWriteRepository<>),
4240
typeof(IResourceWriteRepository<,>),
43-
typeof(IResourceReadRepository<>),
4441
typeof(IResourceReadRepository<,>)
4542
};
4643

src/JsonApiDotNetCore/Repositories/EntityFrameworkCoreRepository.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -584,19 +584,4 @@ protected virtual async Task SaveChangesAsync(CancellationToken cancellationToke
584584
}
585585
}
586586
}
587-
588-
/// <summary>
589-
/// Implements the foundational Repository layer in the JsonApiDotNetCore architecture that uses Entity Framework Core.
590-
/// </summary>
591-
[PublicAPI]
592-
public class EntityFrameworkCoreRepository<TResource> : EntityFrameworkCoreRepository<TResource, int>, IResourceRepository<TResource>
593-
where TResource : class, IIdentifiable<int>
594-
{
595-
public EntityFrameworkCoreRepository(ITargetedFields targetedFields, IDbContextResolver dbContextResolver, IResourceGraph resourceGraph,
596-
IResourceFactory resourceFactory, IEnumerable<IQueryConstraintProvider> constraintProviders, ILoggerFactory loggerFactory,
597-
IResourceDefinitionAccessor resourceDefinitionAccessor)
598-
: base(targetedFields, dbContextResolver, resourceGraph, resourceFactory, constraintProviders, loggerFactory, resourceDefinitionAccessor)
599-
{
600-
}
601-
}
602587
}

src/JsonApiDotNetCore/Repositories/IResourceReadRepository.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88

99
namespace JsonApiDotNetCore.Repositories
1010
{
11-
/// <inheritdoc />
12-
public interface IResourceReadRepository<TResource> : IResourceReadRepository<TResource, int>
13-
where TResource : class, IIdentifiable<int>
14-
{
15-
}
16-
1711
/// <summary>
1812
/// Groups read operations.
1913
/// </summary>

src/JsonApiDotNetCore/Repositories/IResourceRepository.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
using JetBrains.Annotations;
21
using JsonApiDotNetCore.Resources;
32

43
namespace JsonApiDotNetCore.Repositories
54
{
6-
/// <summary>
7-
/// Represents the foundational Resource Repository layer in the JsonApiDotNetCore architecture that provides data access to an underlying store.
8-
/// </summary>
9-
/// <typeparam name="TResource">
10-
/// The resource type.
11-
/// </typeparam>
12-
[PublicAPI]
13-
public interface IResourceRepository<TResource>
14-
: IResourceRepository<TResource, int>, IResourceReadRepository<TResource>, IResourceWriteRepository<TResource>
15-
where TResource : class, IIdentifiable<int>
16-
{
17-
}
18-
195
/// <summary>
206
/// Represents the foundational Resource Repository layer in the JsonApiDotNetCore architecture that provides data access to an underlying store.
217
/// </summary>

src/JsonApiDotNetCore/Repositories/IResourceWriteRepository.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77

88
namespace JsonApiDotNetCore.Repositories
99
{
10-
/// <inheritdoc />
11-
public interface IResourceWriteRepository<TResource> : IResourceWriteRepository<TResource, int>
12-
where TResource : class, IIdentifiable<int>
13-
{
14-
}
15-
1610
/// <summary>
1711
/// Groups write operations.
1812
/// </summary>

src/JsonApiDotNetCore/Repositories/ResourceRepositoryAccessor.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,6 @@ protected object ResolveReadRepository(Type resourceClrType)
130130

131131
protected virtual object ResolveReadRepository(ResourceType resourceType)
132132
{
133-
if (resourceType.IdentityClrType == typeof(int))
134-
{
135-
Type intRepositoryType = typeof(IResourceReadRepository<>).MakeGenericType(resourceType.ClrType);
136-
object intRepository = _serviceProvider.GetService(intRepositoryType);
137-
138-
if (intRepository != null)
139-
{
140-
return intRepository;
141-
}
142-
}
143-
144133
Type resourceDefinitionType = typeof(IResourceReadRepository<,>).MakeGenericType(resourceType.ClrType, resourceType.IdentityClrType);
145134
return _serviceProvider.GetRequiredService(resourceDefinitionType);
146135
}
@@ -170,17 +159,6 @@ protected virtual object ResolveWriteRepository(Type resourceClrType)
170159
{
171160
ResourceType resourceType = _resourceGraph.GetResourceType(resourceClrType);
172161

173-
if (resourceType.IdentityClrType == typeof(int))
174-
{
175-
Type intRepositoryType = typeof(IResourceWriteRepository<>).MakeGenericType(resourceType.ClrType);
176-
object intRepository = _serviceProvider.GetService(intRepositoryType);
177-
178-
if (intRepository != null)
179-
{
180-
return intRepository;
181-
}
182-
}
183-
184162
Type resourceDefinitionType = typeof(IResourceWriteRepository<,>).MakeGenericType(resourceType.ClrType, resourceType.IdentityClrType);
185163
return _serviceProvider.GetRequiredService(resourceDefinitionType);
186164
}

test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void Can_add_resource_repository_from_current_assembly_to_container()
110110
// Assert
111111
ServiceProvider services = _services.BuildServiceProvider();
112112

113-
var resourceRepository = services.GetRequiredService<IResourceRepository<TestResource>>();
113+
var resourceRepository = services.GetRequiredService<IResourceRepository<TestResource, int>>();
114114
resourceRepository.Should().BeOfType<TestResourceRepository>();
115115
}
116116

test/DiscoveryTests/TestResourceRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace DiscoveryTests
1010
{
1111
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
12-
public sealed class TestResourceRepository : EntityFrameworkCoreRepository<TestResource>
12+
public sealed class TestResourceRepository : EntityFrameworkCoreRepository<TestResource, int>
1313
{
1414
public TestResourceRepository(ITargetedFields targetedFields, IDbContextResolver dbContextResolver, IResourceGraph resourceGraph,
1515
IResourceFactory resourceFactory, IEnumerable<IQueryConstraintProvider> constraintProviders, ILoggerFactory loggerFactory,

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Transactions/PerformerRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace JsonApiDotNetCoreTests.IntegrationTests.AtomicOperations.Transactions
1212
{
1313
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
14-
public sealed class PerformerRepository : IResourceRepository<Performer>
14+
public sealed class PerformerRepository : IResourceRepository<Performer, int>
1515
{
1616
public Task<IReadOnlyCollection<Performer>> GetAsync(QueryLayer layer, CancellationToken cancellationToken)
1717
{

test/JsonApiDotNetCoreTests/IntegrationTests/CompositeKeys/CarCompositeKeyAwareRepository.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,4 @@ private void RecursiveRewriteFilterInLayer(QueryLayer queryLayer)
5252
}
5353
}
5454
}
55-
56-
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
57-
public class CarCompositeKeyAwareRepository<TResource> : CarCompositeKeyAwareRepository<TResource, int>, IResourceRepository<TResource>
58-
where TResource : class, IIdentifiable<int>
59-
{
60-
public CarCompositeKeyAwareRepository(ITargetedFields targetedFields, IDbContextResolver dbContextResolver, IResourceGraph resourceGraph,
61-
IResourceFactory resourceFactory, IEnumerable<IQueryConstraintProvider> constraintProviders, ILoggerFactory loggerFactory,
62-
IResourceDefinitionAccessor resourceDefinitionAccessor)
63-
: base(targetedFields, dbContextResolver, resourceGraph, resourceFactory, constraintProviders, loggerFactory, resourceDefinitionAccessor)
64-
{
65-
}
66-
}
6755
}

test/JsonApiDotNetCoreTests/IntegrationTests/CompositeKeys/CompositeKeyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public CompositeKeyTests(IntegrationTestContext<TestableStartup<CompositeDbConte
2828
testContext.ConfigureServicesAfterStartup(services =>
2929
{
3030
services.AddResourceRepository<CarCompositeKeyAwareRepository<Car, string>>();
31-
services.AddResourceRepository<CarCompositeKeyAwareRepository<Dealership>>();
31+
services.AddResourceRepository<CarCompositeKeyAwareRepository<Dealership, int>>();
3232
});
3333

3434
var options = (JsonApiOptions)testContext.Factory.Services.GetRequiredService<IJsonApiOptions>();

test/JsonApiDotNetCoreTests/IntegrationTests/EagerLoading/BuildingRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace JsonApiDotNetCoreTests.IntegrationTests.EagerLoading
1212
{
1313
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
14-
public sealed class BuildingRepository : EntityFrameworkCoreRepository<Building>
14+
public sealed class BuildingRepository : EntityFrameworkCoreRepository<Building, int>
1515
{
1616
public BuildingRepository(ITargetedFields targetedFields, IDbContextResolver dbContextResolver, IResourceGraph resourceGraph,
1717
IResourceFactory resourceFactory, IEnumerable<IQueryConstraintProvider> constraintProviders, ILoggerFactory loggerFactory,

test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/SparseFieldSets/ResultCapturingRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace JsonApiDotNetCoreTests.IntegrationTests.QueryStrings.SparseFieldSets
1414
/// Enables sparse fieldset tests to verify which fields were (not) retrieved from the database.
1515
/// </summary>
1616
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
17-
public sealed class ResultCapturingRepository<TResource> : EntityFrameworkCoreRepository<TResource>
18-
where TResource : class, IIdentifiable<int>
17+
public sealed class ResultCapturingRepository<TResource, TId> : EntityFrameworkCoreRepository<TResource, TId>
18+
where TResource : class, IIdentifiable<TId>
1919
{
2020
private readonly ResourceCaptureStore _captureStore;
2121

test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/SparseFieldSets/SparseFieldSetTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public SparseFieldSetTests(IntegrationTestContext<TestableStartup<QueryStringDbC
2929
{
3030
services.AddSingleton<ResourceCaptureStore>();
3131

32-
services.AddResourceRepository<ResultCapturingRepository<Blog>>();
33-
services.AddResourceRepository<ResultCapturingRepository<BlogPost>>();
34-
services.AddResourceRepository<ResultCapturingRepository<WebAccount>>();
32+
services.AddResourceRepository<ResultCapturingRepository<Blog, int>>();
33+
services.AddResourceRepository<ResultCapturingRepository<BlogPost, int>>();
34+
services.AddResourceRepository<ResultCapturingRepository<WebAccount, int>>();
3535
});
3636
}
3737

test/UnitTests/Extensions/ServiceCollectionExtensionsTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ public void AddResourceRepository_Registers_All_Shorthand_Repository_Interfaces(
110110

111111
// Assert
112112
ServiceProvider provider = services.BuildServiceProvider();
113-
Assert.IsType<IntResourceRepository>(provider.GetRequiredService(typeof(IResourceRepository<IntResource>)));
114-
Assert.IsType<IntResourceRepository>(provider.GetRequiredService(typeof(IResourceReadRepository<IntResource>)));
115-
Assert.IsType<IntResourceRepository>(provider.GetRequiredService(typeof(IResourceWriteRepository<IntResource>)));
113+
Assert.IsType<IntResourceRepository>(provider.GetRequiredService(typeof(IResourceRepository<IntResource, int>)));
114+
Assert.IsType<IntResourceRepository>(provider.GetRequiredService(typeof(IResourceReadRepository<IntResource, int>)));
115+
Assert.IsType<IntResourceRepository>(provider.GetRequiredService(typeof(IResourceWriteRepository<IntResource, int>)));
116116
}
117117

118118
[Fact]
@@ -300,7 +300,7 @@ public Task RemoveFromToManyRelationshipAsync(Guid leftId, string relationshipNa
300300
}
301301

302302
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
303-
private sealed class IntResourceRepository : IResourceRepository<IntResource>
303+
private sealed class IntResourceRepository : IResourceRepository<IntResource, int>
304304
{
305305
public Task<IReadOnlyCollection<IntResource>> GetAsync(QueryLayer layer, CancellationToken cancellationToken)
306306
{

0 commit comments

Comments
 (0)