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
TResourceThe resource type.
TIdThe 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
repositoryAccessorIResourceRepositoryAccessorqueryLayerComposerIQueryLayerComposerpaginationContextIPaginationContextoptionsIJsonApiOptionsloggerFactoryILoggerFactoryrequestIJsonApiRequestresourceChangeTrackerIResourceChangeTracker<TResource>resourceDefinitionAccessorIResourceDefinitionAccessor
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
leftIdTIdIdentifies the left side of the relationship.
relationshipNamestringThe relationship to add resources to.
rightResourceIdsISet<IIdentifiable>The set of resources to add to the relationship.
cancellationTokenCancellationTokenPropagates notification that request handling should be canceled.
Returns
AssertPrimaryResourceDoesNotExistAsync(TResource, CancellationToken)
protected Task AssertPrimaryResourceDoesNotExistAsync(TResource resource, CancellationToken cancellationToken)
Parameters
resourceTResourcecancellationTokenCancellationToken
Returns
AssertResourcesToAssignInRelationshipsExistAsync(TResource, CancellationToken)
protected Task AssertResourcesToAssignInRelationshipsExistAsync(TResource primaryResource, CancellationToken cancellationToken)
Parameters
primaryResourceTResourcecancellationTokenCancellationToken
Returns
AssertRightResourcesExistAsync(object?, CancellationToken)
protected Task<object?> AssertRightResourcesExistAsync(object? rightValue, CancellationToken cancellationToken)
Parameters
rightValueobjectcancellationTokenCancellationToken
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
resourceTResourcecancellationTokenCancellationToken
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
idTIdcancellationTokenCancellationToken
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
cancellationTokenCancellationToken
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
idTIdcancellationTokenCancellationToken
Returns
- Task<TResource>
GetPrimaryResourceByIdAsync(TId, TopFieldSelection, CancellationToken)
protected Task<TResource> GetPrimaryResourceByIdAsync(TId id, TopFieldSelection fieldSelection, CancellationToken cancellationToken)
Parameters
idTIdfieldSelectionTopFieldSelectioncancellationTokenCancellationToken
Returns
- Task<TResource>
GetPrimaryResourceForUpdateAsync(TId, CancellationToken)
protected Task<TResource> GetPrimaryResourceForUpdateAsync(TId id, CancellationToken cancellationToken)
Parameters
idTIdcancellationTokenCancellationToken
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
idTIdrelationshipNamestringcancellationTokenCancellationToken
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
idTIdrelationshipNamestringcancellationTokenCancellationToken
Returns
InitializeResourceAsync(TResource, CancellationToken)
protected virtual Task InitializeResourceAsync(TResource resourceForDatabase, CancellationToken cancellationToken)
Parameters
resourceForDatabaseTResourcecancellationTokenCancellationToken
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
leftIdTIdIdentifies the left side of the relationship.
relationshipNamestringThe relationship to remove resources from.
rightResourceIdsISet<IIdentifiable>The set of resources to remove from the relationship.
cancellationTokenCancellationTokenPropagates 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
leftIdTIdIdentifies the left side of the relationship.
relationshipNamestringThe relationship for which to perform a complete replacement.
rightValueobjectThe resource or set of resources to assign to the relationship.
cancellationTokenCancellationTokenPropagates 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
idTIdresourceTResourcecancellationTokenCancellationToken
Returns
- Task<TResource>