Class JsonApiResourceService<TResource, TId>
- Namespace
- JsonApiDotNetCore.Services
- Assembly
- JsonApiDotNetCore.dll
Represents the foundational Resource Service layer in the JsonApiDotNetCore architecture that uses a Resource Repository for data access.
[PublicAPI]
public class JsonApiResourceService<TResource, TId> : IResourceService<TResource, TId>, IResourceCommandService<TResource, TId>, ICreateService<TResource, TId>, IAddToRelationshipService<TResource, TId>, IUpdateService<TResource, TId>, ISetRelationshipService<TResource, TId>, IDeleteService<TResource, TId>, IRemoveFromRelationshipService<TResource, TId>, IResourceQueryService<TResource, TId>, IGetAllService<TResource, TId>, IGetByIdService<TResource, TId>, IGetRelationshipService<TResource, TId>, IGetSecondaryService<TResource, TId> where TResource : class, IIdentifiable<TId>
Type Parameters
TResource
The resource type.
TId
The resource identifier type.
- Inheritance
-
JsonApiResourceService<TResource, TId>
- Implements
-
IResourceService<TResource, TId>IResourceCommandService<TResource, TId>ICreateService<TResource, TId>IAddToRelationshipService<TResource, TId>IUpdateService<TResource, TId>ISetRelationshipService<TResource, TId>IDeleteService<TResource, TId>IRemoveFromRelationshipService<TResource, TId>IResourceQueryService<TResource, TId>IGetAllService<TResource, TId>IGetByIdService<TResource, TId>IGetRelationshipService<TResource, TId>IGetSecondaryService<TResource, TId>
- Inherited Members
Constructors
JsonApiResourceService(IResourceRepositoryAccessor, IQueryLayerComposer, IPaginationContext, IJsonApiOptions, ILoggerFactory, IJsonApiRequest, IResourceChangeTracker<TResource>, IResourceDefinitionAccessor)
public JsonApiResourceService(IResourceRepositoryAccessor repositoryAccessor, IQueryLayerComposer queryLayerComposer, IPaginationContext paginationContext, IJsonApiOptions options, ILoggerFactory loggerFactory, IJsonApiRequest request, IResourceChangeTracker<TResource> resourceChangeTracker, IResourceDefinitionAccessor resourceDefinitionAccessor)
Parameters
repositoryAccessor
IResourceRepositoryAccessorqueryLayerComposer
IQueryLayerComposerpaginationContext
IPaginationContextoptions
IJsonApiOptionsloggerFactory
ILoggerFactoryrequest
IJsonApiRequestresourceChangeTracker
IResourceChangeTracker<TResource>resourceDefinitionAccessor
IResourceDefinitionAccessor
Methods
AddToToManyRelationshipAsync(TId, string, ISet<IIdentifiable>, CancellationToken)
Handles a JSON:API request to add resources to a to-many relationship.
public virtual Task AddToToManyRelationshipAsync(TId leftId, string relationshipName, ISet<IIdentifiable> rightResourceIds, CancellationToken cancellationToken)
Parameters
leftId
TIdIdentifies the left side of the relationship.
relationshipName
stringThe relationship to add resources to.
rightResourceIds
ISet<IIdentifiable>The set of resources to add to the relationship.
cancellationToken
CancellationTokenPropagates notification that request handling should be canceled.
Returns
AssertPrimaryResourceDoesNotExistAsync(TResource, CancellationToken)
protected Task AssertPrimaryResourceDoesNotExistAsync(TResource resource, CancellationToken cancellationToken)
Parameters
resource
TResourcecancellationToken
CancellationToken
Returns
AssertResourcesToAssignInRelationshipsExistAsync(TResource, CancellationToken)
protected Task AssertResourcesToAssignInRelationshipsExistAsync(TResource primaryResource, CancellationToken cancellationToken)
Parameters
primaryResource
TResourcecancellationToken
CancellationToken
Returns
AssertRightResourcesExistAsync(object?, CancellationToken)
protected Task<object?> AssertRightResourcesExistAsync(object? rightValue, CancellationToken cancellationToken)
Parameters
rightValue
objectcancellationToken
CancellationToken
Returns
CreateAsync(TResource, CancellationToken)
Handles a JSON:API request to create a new resource with attributes, relationships or both.
public virtual Task<TResource?> CreateAsync(TResource resource, CancellationToken cancellationToken)
Parameters
resource
TResourcecancellationToken
CancellationToken
Returns
- Task<TResource>
DeleteAsync(TId, CancellationToken)
Handles a JSON:API request to delete an existing resource.
public virtual Task DeleteAsync(TId id, CancellationToken cancellationToken)
Parameters
id
TIdcancellationToken
CancellationToken
Returns
GetAsync(CancellationToken)
Handles a JSON:API request to retrieve a collection of resources for a primary endpoint.
public virtual Task<IReadOnlyCollection<TResource>> GetAsync(CancellationToken cancellationToken)
Parameters
cancellationToken
CancellationToken
Returns
- Task<IReadOnlyCollection<TResource>>
GetAsync(TId, CancellationToken)
Handles a JSON:API request to retrieve a single resource for a primary endpoint.
public virtual Task<TResource> GetAsync(TId id, CancellationToken cancellationToken)
Parameters
id
TIdcancellationToken
CancellationToken
Returns
- Task<TResource>
GetPrimaryResourceByIdAsync(TId, TopFieldSelection, CancellationToken)
protected Task<TResource> GetPrimaryResourceByIdAsync(TId id, TopFieldSelection fieldSelection, CancellationToken cancellationToken)
Parameters
id
TIdfieldSelection
TopFieldSelectioncancellationToken
CancellationToken
Returns
- Task<TResource>
GetPrimaryResourceForUpdateAsync(TId, CancellationToken)
protected Task<TResource> GetPrimaryResourceForUpdateAsync(TId id, CancellationToken cancellationToken)
Parameters
id
TIdcancellationToken
CancellationToken
Returns
- Task<TResource>
GetRelationshipAsync(TId, string, CancellationToken)
Handles a JSON:API request to retrieve a single relationship.
public virtual Task<object?> GetRelationshipAsync(TId id, string relationshipName, CancellationToken cancellationToken)
Parameters
id
TIdrelationshipName
stringcancellationToken
CancellationToken
Returns
GetSecondaryAsync(TId, string, CancellationToken)
Handles a JSON:API request to retrieve a single resource or a collection of resources for a secondary endpoint, such as /articles/1/author or /articles/1/revisions.
public virtual Task<object?> GetSecondaryAsync(TId id, string relationshipName, CancellationToken cancellationToken)
Parameters
id
TIdrelationshipName
stringcancellationToken
CancellationToken
Returns
InitializeResourceAsync(TResource, CancellationToken)
protected virtual Task InitializeResourceAsync(TResource resourceForDatabase, CancellationToken cancellationToken)
Parameters
resourceForDatabase
TResourcecancellationToken
CancellationToken
Returns
RemoveFromToManyRelationshipAsync(TId, string, ISet<IIdentifiable>, CancellationToken)
Handles a JSON:API request to remove resources from a to-many relationship.
public virtual Task RemoveFromToManyRelationshipAsync(TId leftId, string relationshipName, ISet<IIdentifiable> rightResourceIds, CancellationToken cancellationToken)
Parameters
leftId
TIdIdentifies the left side of the relationship.
relationshipName
stringThe relationship to remove resources from.
rightResourceIds
ISet<IIdentifiable>The set of resources to remove from the relationship.
cancellationToken
CancellationTokenPropagates notification that request handling should be canceled.
Returns
SetRelationshipAsync(TId, string, object?, CancellationToken)
Handles a JSON:API request to perform a complete replacement of a relationship on an existing resource.
public virtual Task SetRelationshipAsync(TId leftId, string relationshipName, object? rightValue, CancellationToken cancellationToken)
Parameters
leftId
TIdIdentifies the left side of the relationship.
relationshipName
stringThe relationship for which to perform a complete replacement.
rightValue
objectThe resource or set of resources to assign to the relationship.
cancellationToken
CancellationTokenPropagates notification that request handling should be canceled.
Returns
UpdateAsync(TId, TResource, CancellationToken)
Handles a JSON:API request to update the attributes and/or relationships of an existing resource. Only the values of sent attributes are replaced. And only the values of sent relationships are replaced.
public virtual Task<TResource?> UpdateAsync(TId id, TResource resource, CancellationToken cancellationToken)
Parameters
id
TIdresource
TResourcecancellationToken
CancellationToken
Returns
- Task<TResource>