Class ResourceGraph
- Namespace
- JsonApiDotNetCore.Configuration
- Assembly
- JsonApiDotNetCore.dll
Metadata about the shape of JSON:API resources that your API serves and the relationships between them. The resource graph is built at application startup and is exposed as a singleton through Dependency Injection.
[PublicAPI]
public sealed class ResourceGraph : IResourceGraph
- Inheritance
-
ResourceGraph
- Implements
- Inherited Members
Constructors
ResourceGraph(IReadOnlySet<ResourceType>)
public ResourceGraph(IReadOnlySet<ResourceType> resourceTypeSet)
Parameters
resourceTypeSet
IReadOnlySet<ResourceType>
Methods
FindResourceType(string)
Attempts to get the metadata for the resource that is publicly exposed by the specified name. Returns null
when not found.
public ResourceType? FindResourceType(string publicName)
Parameters
publicName
string
Returns
FindResourceType(Type)
Attempts to get metadata for the resource of the specified CLR type. Returns null
when not found.
public ResourceType? FindResourceType(Type resourceClrType)
Parameters
resourceClrType
Type
Returns
GetAttributes<TResource>(Expression<Func<TResource, object?>>)
Gets the attributes for TResource
that are targeted by the selector.
public IReadOnlyCollection<AttrAttribute> GetAttributes<TResource>(Expression<Func<TResource, object?>> selector) where TResource : class, IIdentifiable
Parameters
selector
Expression<Func<TResource, object>>Should be of the form: (TResource resource) => new { resource.Attribute1, resource.Attribute2 }
Returns
Type Parameters
TResource
The resource CLR type for which to retrieve attributes.
GetFields<TResource>(Expression<Func<TResource, object?>>)
Gets the fields (attributes and relationships) for TResource
that are targeted by the selector.
public IReadOnlyCollection<ResourceFieldAttribute> GetFields<TResource>(Expression<Func<TResource, object?>> selector) where TResource : class, IIdentifiable
Parameters
selector
Expression<Func<TResource, object>>Should be of the form: (TResource resource) => new { resource.Attribute1, resource.Relationship2 }
Returns
Type Parameters
TResource
The resource CLR type for which to retrieve fields.
GetRelationships<TResource>(Expression<Func<TResource, object?>>)
Gets the relationships for TResource
that are targeted by the selector.
public IReadOnlyCollection<RelationshipAttribute> GetRelationships<TResource>(Expression<Func<TResource, object?>> selector) where TResource : class, IIdentifiable
Parameters
selector
Expression<Func<TResource, object>>Should be of the form: (TResource resource) => new { resource.Relationship1, resource.Relationship2 }
Returns
Type Parameters
TResource
The resource CLR type for which to retrieve relationships.
GetResourceType(string)
Gets the metadata for the resource that is publicly exposed by the specified name. Throws an InvalidOperationException when not found.
public ResourceType GetResourceType(string publicName)
Parameters
publicName
string
Returns
GetResourceType(Type)
Gets the metadata for the resource of the specified CLR type. Throws an InvalidOperationException when not found.
public ResourceType GetResourceType(Type resourceClrType)
Parameters
resourceClrType
Type
Returns
GetResourceType<TResource>()
Gets the metadata for the resource of the specified CLR type. Throws an InvalidOperationException when not found.
public ResourceType GetResourceType<TResource>() where TResource : class, IIdentifiable
Returns
Type Parameters
TResource
GetResourceTypes()
Gets the metadata for all registered resources.
public IReadOnlySet<ResourceType> GetResourceTypes()