-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathTodoItemService.cs
38 lines (33 loc) · 1.44 KB
/
TodoItemService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using JetBrains.Annotations;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Queries;
using JsonApiDotNetCore.Queries.QueryableBuilding;
using JsonApiDotNetCore.Resources;
using Microsoft.EntityFrameworkCore.Metadata;
using NoEntityFrameworkExample.Data;
using NoEntityFrameworkExample.Models;
namespace NoEntityFrameworkExample.Services;
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
public sealed class TodoItemService(
IJsonApiOptions options, IResourceGraph resourceGraph, IQueryLayerComposer queryLayerComposer, IPaginationContext paginationContext,
IEnumerable<IQueryConstraintProvider> constraintProviders, IQueryableBuilder queryableBuilder, IReadOnlyModel entityModel, ILoggerFactory loggerFactory)
: InMemoryResourceService<TodoItem, long>(options, resourceGraph, queryLayerComposer, paginationContext, constraintProviders, queryableBuilder, entityModel,
loggerFactory)
{
protected override IEnumerable<IIdentifiable> GetDataSource(ResourceType resourceType)
{
if (resourceType.ClrType == typeof(TodoItem))
{
return Database.TodoItems;
}
if (resourceType.ClrType == typeof(Person))
{
return Database.People;
}
if (resourceType.ClrType == typeof(Tag))
{
return Database.Tags;
}
throw new InvalidOperationException($"Unknown data source '{resourceType.ClrType}'.");
}
}