Skip to content

Commit 8870ccd

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

File tree

18 files changed

+17
-96
lines changed

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

0 commit comments

Comments
 (0)