Skip to content

Commit 92bc642

Browse files
author
Bart Koelman
committed
Removed single-parameter resource services
1 parent 425c4df commit 92bc642

File tree

92 files changed

+99
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+99
-253
lines changed

src/Examples/GettingStarted/Controllers/BooksController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace GettingStarted.Controllers
88
{
99
public sealed class BooksController : JsonApiController<Book, int>
1010
{
11-
public BooksController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<Book> resourceService)
11+
public BooksController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<Book, int> resourceService)
1212
: base(options, loggerFactory, resourceService)
1313
{
1414
}

src/Examples/GettingStarted/Controllers/PeopleController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace GettingStarted.Controllers
88
{
99
public sealed class PeopleController : JsonApiController<Person, int>
1010
{
11-
public PeopleController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<Person> resourceService)
11+
public PeopleController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<Person, int> resourceService)
1212
: base(options, loggerFactory, resourceService)
1313
{
1414
}

src/Examples/JsonApiDotNetCoreExample/Controllers/PeopleController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace JsonApiDotNetCoreExample.Controllers
88
{
99
public sealed class PeopleController : JsonApiController<Person, int>
1010
{
11-
public PeopleController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<Person> resourceService)
11+
public PeopleController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<Person, int> resourceService)
1212
: base(options, loggerFactory, resourceService)
1313
{
1414
}

src/Examples/JsonApiDotNetCoreExample/Controllers/TagsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace JsonApiDotNetCoreExample.Controllers
88
{
99
public sealed class TagsController : JsonApiController<Tag, int>
1010
{
11-
public TagsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<Tag> resourceService)
11+
public TagsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<Tag, int> resourceService)
1212
: base(options, loggerFactory, resourceService)
1313
{
1414
}

src/Examples/JsonApiDotNetCoreExample/Controllers/TodoItemsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace JsonApiDotNetCoreExample.Controllers
88
{
99
public sealed class TodoItemsController : JsonApiController<TodoItem, int>
1010
{
11-
public TodoItemsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<TodoItem> resourceService)
11+
public TodoItemsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<TodoItem, int> resourceService)
1212
: base(options, loggerFactory, resourceService)
1313
{
1414
}

src/Examples/MultiDbContextExample/Controllers/ResourceAsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace MultiDbContextExample.Controllers
88
{
99
public sealed class ResourceAsController : JsonApiController<ResourceA, int>
1010
{
11-
public ResourceAsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<ResourceA> resourceService)
11+
public ResourceAsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<ResourceA, int> resourceService)
1212
: base(options, loggerFactory, resourceService)
1313
{
1414
}

src/Examples/MultiDbContextExample/Controllers/ResourceBsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace MultiDbContextExample.Controllers
88
{
99
public sealed class ResourceBsController : JsonApiController<ResourceB, int>
1010
{
11-
public ResourceBsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<ResourceB> resourceService)
11+
public ResourceBsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<ResourceB, int> resourceService)
1212
: base(options, loggerFactory, resourceService)
1313
{
1414
}

src/Examples/NoEntityFrameworkExample/Controllers/WorkItemsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace NoEntityFrameworkExample.Controllers
88
{
99
public sealed class WorkItemsController : JsonApiController<WorkItem, int>
1010
{
11-
public WorkItemsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<WorkItem> resourceService)
11+
public WorkItemsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IResourceService<WorkItem, int> resourceService)
1212
: base(options, loggerFactory, resourceService)
1313
{
1414
}

src/Examples/NoEntityFrameworkExample/Services/WorkItemService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace NoEntityFrameworkExample.Services
1616
{
1717
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
18-
public sealed class WorkItemService : IResourceService<WorkItem>
18+
public sealed class WorkItemService : IResourceService<WorkItem, int>
1919
{
2020
private readonly string _connectionString;
2121

src/Examples/NoEntityFrameworkExample/Startup.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using JetBrains.Annotations;
33
using JsonApiDotNetCore.Configuration;
4-
using JsonApiDotNetCore.Services;
54
using Microsoft.AspNetCore.Builder;
65
using Microsoft.EntityFrameworkCore;
76
using Microsoft.Extensions.Configuration;
@@ -27,7 +26,7 @@ public void ConfigureServices(IServiceCollection services)
2726
{
2827
services.AddJsonApi(options => options.Namespace = "api/v1", resources: builder => builder.Add<WorkItem>("workItems"));
2928

30-
services.AddScoped<IResourceService<WorkItem>, WorkItemService>();
29+
services.AddResourceService<WorkItemService>();
3130

3231
services.AddDbContext<AppDbContext>(options => options.UseNpgsql(_connectionString));
3332
}

src/Examples/ReportsExample/Controllers/ReportsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ReportsExample.Controllers
1212
[Route("api/[controller]")]
1313
public class ReportsController : BaseJsonApiController<Report, int>
1414
{
15-
public ReportsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IGetAllService<Report> getAllService)
15+
public ReportsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IGetAllService<Report, int> getAllService)
1616
: base(options, loggerFactory, getAllService)
1717
{
1818
}

src/Examples/ReportsExample/Services/ReportService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace ReportsExample.Services
1010
{
1111
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
12-
public class ReportService : IGetAllService<Report>
12+
public class ReportService : IGetAllService<Report, int>
1313
{
1414
private readonly ILogger<ReportService> _logger;
1515

src/JsonApiDotNetCore/Configuration/JsonApiApplicationBuilder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,16 @@ private void AddRepositoryLayer()
198198

199199
private void AddServiceLayer()
200200
{
201-
RegisterImplementationForOpenInterfaces(ServiceDiscoveryFacade.ServiceInterfaces, typeof(JsonApiResourceService<>),
202-
typeof(JsonApiResourceService<,>));
201+
RegisterImplementationForOpenInterfaces(ServiceDiscoveryFacade.ServiceInterfaces, null, typeof(JsonApiResourceService<,>));
203202
}
204203

205204
private void RegisterImplementationForOpenInterfaces(HashSet<Type> openGenericInterfaces, Type intImplementation, Type implementation)
206205
{
207206
foreach (Type openGenericInterface in openGenericInterfaces)
208207
{
209-
Type implementationType = openGenericInterface.GetGenericArguments().Length == 1 ? intImplementation : implementation;
208+
Type implementationType = openGenericInterface.GetGenericArguments().Length == 1 && intImplementation != null
209+
? intImplementation
210+
: implementation;
210211

211212
_services.TryAddScoped(openGenericInterface, implementationType);
212213
}

src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,18 @@ public sealed class ServiceDiscoveryFacade
1919
{
2020
internal static readonly HashSet<Type> ServiceInterfaces = new()
2121
{
22-
typeof(IResourceService<>),
2322
typeof(IResourceService<,>),
24-
typeof(IResourceCommandService<>),
2523
typeof(IResourceCommandService<,>),
26-
typeof(IResourceQueryService<>),
2724
typeof(IResourceQueryService<,>),
28-
typeof(IGetAllService<>),
2925
typeof(IGetAllService<,>),
30-
typeof(IGetByIdService<>),
3126
typeof(IGetByIdService<,>),
32-
typeof(IGetSecondaryService<>),
3327
typeof(IGetSecondaryService<,>),
34-
typeof(IGetRelationshipService<>),
3528
typeof(IGetRelationshipService<,>),
36-
typeof(ICreateService<>),
3729
typeof(ICreateService<,>),
38-
typeof(IAddToRelationshipService<>),
3930
typeof(IAddToRelationshipService<,>),
40-
typeof(IUpdateService<>),
4131
typeof(IUpdateService<,>),
42-
typeof(ISetRelationshipService<>),
4332
typeof(ISetRelationshipService<,>),
44-
typeof(IDeleteService<>),
4533
typeof(IDeleteService<,>),
46-
typeof(IRemoveFromRelationshipService<>),
4734
typeof(IRemoveFromRelationshipService<,>)
4835
};
4936

src/JsonApiDotNetCore/Services/IAddToRelationshipService.cs

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

99
namespace JsonApiDotNetCore.Services
1010
{
11-
/// <inheritdoc />
12-
public interface IAddToRelationshipService<TResource> : IAddToRelationshipService<TResource, int>
13-
where TResource : class, IIdentifiable<int>
14-
{
15-
}
16-
1711
/// <summary />
1812
[PublicAPI]
1913
public interface IAddToRelationshipService<TResource, in TId>

src/JsonApiDotNetCore/Services/ICreateService.cs

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

55
namespace JsonApiDotNetCore.Services
66
{
7-
/// <inheritdoc />
8-
public interface ICreateService<TResource> : ICreateService<TResource, int>
9-
where TResource : class, IIdentifiable<int>
10-
{
11-
}
12-
137
/// <summary />
148
public interface ICreateService<TResource, in TId>
159
where TResource : class, IIdentifiable<TId>

src/JsonApiDotNetCore/Services/IDeleteService.cs

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

77
namespace JsonApiDotNetCore.Services
88
{
9-
/// <inheritdoc />
10-
public interface IDeleteService<TResource> : IDeleteService<TResource, int>
11-
where TResource : class, IIdentifiable<int>
12-
{
13-
}
14-
159
/// <summary />
1610
public interface IDeleteService<TResource, in TId>
1711
where TResource : class, IIdentifiable<TId>

src/JsonApiDotNetCore/Services/IGetAllService.cs

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

66
namespace JsonApiDotNetCore.Services
77
{
8-
/// <inheritdoc />
9-
public interface IGetAllService<TResource> : IGetAllService<TResource, int>
10-
where TResource : class, IIdentifiable<int>
11-
{
12-
}
13-
148
/// <summary />
159
public interface IGetAllService<TResource, in TId>
1610
where TResource : class, IIdentifiable<TId>

src/JsonApiDotNetCore/Services/IGetByIdService.cs

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

55
namespace JsonApiDotNetCore.Services
66
{
7-
/// <inheritdoc />
8-
public interface IGetByIdService<TResource> : IGetByIdService<TResource, int>
9-
where TResource : class, IIdentifiable<int>
10-
{
11-
}
12-
137
/// <summary />
148
public interface IGetByIdService<TResource, in TId>
159
where TResource : class, IIdentifiable<TId>

src/JsonApiDotNetCore/Services/IGetRelationshipService.cs

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

77
namespace JsonApiDotNetCore.Services
88
{
9-
/// <inheritdoc />
10-
public interface IGetRelationshipService<TResource> : IGetRelationshipService<TResource, int>
11-
where TResource : class, IIdentifiable<int>
12-
{
13-
}
14-
159
/// <summary />
1610
public interface IGetRelationshipService<TResource, in TId>
1711
where TResource : class, IIdentifiable<TId>

src/JsonApiDotNetCore/Services/IGetSecondaryService.cs

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

77
namespace JsonApiDotNetCore.Services
88
{
9-
/// <inheritdoc />
10-
public interface IGetSecondaryService<TResource> : IGetSecondaryService<TResource, int>
11-
where TResource : class, IIdentifiable<int>
12-
{
13-
}
14-
159
/// <summary />
1610
public interface IGetSecondaryService<TResource, in TId>
1711
where TResource : class, IIdentifiable<TId>

src/JsonApiDotNetCore/Services/IRemoveFromRelationshipService.cs

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

88
namespace JsonApiDotNetCore.Services
99
{
10-
/// <inheritdoc />
11-
public interface IRemoveFromRelationshipService<TResource> : IRemoveFromRelationshipService<TResource, int>
12-
where TResource : class, IIdentifiable<int>
13-
{
14-
}
15-
1610
/// <summary />
1711
public interface IRemoveFromRelationshipService<TResource, in TId>
1812
where TResource : class, IIdentifiable<TId>

src/JsonApiDotNetCore/Services/IResourceCommandService.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22

33
namespace JsonApiDotNetCore.Services
44
{
5-
/// <summary>
6-
/// Groups write operations.
7-
/// </summary>
8-
/// <typeparam name="TResource">
9-
/// The resource type.
10-
/// </typeparam>
11-
public interface IResourceCommandService<TResource>
12-
: ICreateService<TResource>, IAddToRelationshipService<TResource>, IUpdateService<TResource>, ISetRelationshipService<TResource>,
13-
IDeleteService<TResource>, IRemoveFromRelationshipService<TResource>, IResourceCommandService<TResource, int>
14-
where TResource : class, IIdentifiable<int>
15-
{
16-
}
17-
185
/// <summary>
196
/// Groups write operations.
207
/// </summary>

src/JsonApiDotNetCore/Services/IResourceQueryService.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22

33
namespace JsonApiDotNetCore.Services
44
{
5-
/// <summary>
6-
/// Groups read operations.
7-
/// </summary>
8-
/// <typeparam name="TResource">
9-
/// The resource type.
10-
/// </typeparam>
11-
public interface IResourceQueryService<TResource>
12-
: IGetAllService<TResource>, IGetByIdService<TResource>, IGetRelationshipService<TResource>, IGetSecondaryService<TResource>,
13-
IResourceQueryService<TResource, int>
14-
where TResource : class, IIdentifiable<int>
15-
{
16-
}
17-
185
/// <summary>
196
/// Groups read operations.
207
/// </summary>

src/JsonApiDotNetCore/Services/IResourceService.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@
22

33
namespace JsonApiDotNetCore.Services
44
{
5-
/// <summary>
6-
/// Represents the foundational Resource Service layer in the JsonApiDotNetCore architecture that uses a Resource Repository for data access.
7-
/// </summary>
8-
/// <typeparam name="TResource">
9-
/// The resource type.
10-
/// </typeparam>
11-
public interface IResourceService<TResource> : IResourceCommandService<TResource>, IResourceQueryService<TResource>, IResourceService<TResource, int>
12-
where TResource : class, IIdentifiable<int>
13-
{
14-
}
15-
165
/// <summary>
176
/// Represents the foundational Resource Service layer in the JsonApiDotNetCore architecture that uses a Resource Repository for data access.
187
/// </summary>

src/JsonApiDotNetCore/Services/ISetRelationshipService.cs

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

77
namespace JsonApiDotNetCore.Services
88
{
9-
/// <inheritdoc />
10-
public interface ISetRelationshipService<TResource> : ISetRelationshipService<TResource, int>
11-
where TResource : class, IIdentifiable<int>
12-
{
13-
}
14-
159
/// <summary />
1610
public interface ISetRelationshipService<TResource, in TId>
1711
where TResource : class, IIdentifiable<TId>

src/JsonApiDotNetCore/Services/IUpdateService.cs

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

55
namespace JsonApiDotNetCore.Services
66
{
7-
/// <inheritdoc />
8-
public interface IUpdateService<TResource> : IUpdateService<TResource, int>
9-
where TResource : class, IIdentifiable<int>
10-
{
11-
}
12-
137
/// <summary />
148
public interface IUpdateService<TResource, in TId>
159
where TResource : class, IIdentifiable<TId>

src/JsonApiDotNetCore/Services/JsonApiResourceService.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -493,23 +493,4 @@ private void AssertHasRelationship(RelationshipAttribute relationship, string na
493493
}
494494
}
495495
}
496-
497-
/// <summary>
498-
/// Represents the foundational Resource Service layer in the JsonApiDotNetCore architecture that uses a Resource Repository for data access.
499-
/// </summary>
500-
/// <typeparam name="TResource">
501-
/// The resource type.
502-
/// </typeparam>
503-
[PublicAPI]
504-
public class JsonApiResourceService<TResource> : JsonApiResourceService<TResource, int>, IResourceService<TResource>
505-
where TResource : class, IIdentifiable<int>
506-
{
507-
public JsonApiResourceService(IResourceRepositoryAccessor repositoryAccessor, IQueryLayerComposer queryLayerComposer,
508-
IPaginationContext paginationContext, IJsonApiOptions options, ILoggerFactory loggerFactory, IJsonApiRequest request,
509-
IResourceChangeTracker<TResource> resourceChangeTracker, IResourceDefinitionAccessor resourceDefinitionAccessor)
510-
: base(repositoryAccessor, queryLayerComposer, paginationContext, options, loggerFactory, request, resourceChangeTracker,
511-
resourceDefinitionAccessor)
512-
{
513-
}
514-
}
515496
}

test/DiscoveryTests/ServiceDiscoveryFacadeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void Can_add_resource_service_from_current_assembly_to_container()
9393
// Assert
9494
ServiceProvider services = _services.BuildServiceProvider();
9595

96-
var resourceService = services.GetRequiredService<IResourceService<TestResource>>();
96+
var resourceService = services.GetRequiredService<IResourceService<TestResource, int>>();
9797
resourceService.Should().BeOfType<TestResourceService>();
9898
}
9999

test/DiscoveryTests/TestResourceService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace DiscoveryTests
1111
{
1212
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
13-
public sealed class TestResourceService : JsonApiResourceService<TestResource>
13+
public sealed class TestResourceService : JsonApiResourceService<TestResource, int>
1414
{
1515
public TestResourceService(IResourceRepositoryAccessor repositoryAccessor, IQueryLayerComposer queryLayerComposer, IPaginationContext paginationContext,
1616
IJsonApiOptions options, ILoggerFactory loggerFactory, IJsonApiRequest request, IResourceChangeTracker<TestResource> resourceChangeTracker,

0 commit comments

Comments
 (0)