Skip to content

Docs: Clarified when/how to register resource definitions #1015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/usage/caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ETag: "356075D903B8FE8D9921201A7E7CD3F9"
}
```

Note: To just poll for changes (without fetching them), send a HEAD request instead:
**Note:** To just poll for changes (without fetching them), send a HEAD request instead:

```http
HEAD /articles?sort=-lastModifiedAt HTTP/1.1
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/extensibility/layer-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on your needs, you may want to replace other parts by deriving from the built-in

## Replacing injected services

**Note:** If you are using auto-discovery, then resource services, repositories and resource definitions will be automatically registered for you.
**Note:** If you're using [auto-discovery](~/usage/resource-graph.md#auto-discovery), then resource services, repositories and resource definitions will be automatically registered for you.

Replacing built-in services is done on a per-resource basis and can be done through dependency injection in your Startup.cs file.
For convenience, extension methods are provided to register layers on all their implemented interfaces.
Expand Down
6 changes: 4 additions & 2 deletions docs/usage/extensibility/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ The repository should then be registered in Startup.cs.
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IResourceRepository<Article>, ArticleRepository>();
services.AddScoped<IResourceReadRepository<Article>, ArticleRepository>();
services.AddScoped<IResourceWriteRepository<Article>, ArticleRepository>();
}
```

In v4.0 we introduced an extension method that you can use to register a resource repository on all of its JsonApiDotNetCore interfaces.
This is helpful when you implement a subset of the resource interfaces and want to register them all in one go.
This is helpful when you implement (a subset of) the resource interfaces and want to register them all in one go.

Note: If you're using service discovery, this happens automatically.
**Note:** If you're using [auto-discovery](~/usage/resource-graph.md#auto-discovery), this happens automatically.

```c#
public class Startup
Expand Down
19 changes: 16 additions & 3 deletions docs/usage/extensibility/resource-definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@
_since v2.3.4_

Resource definitions provide a resource-oriented way to handle custom business logic (irrespective of the originating endpoint).

They are resolved from the dependency injection container, so you can inject dependencies in their constructor.

In v4.2 we introduced an extension method that you can use to register your resource definition.

**Note:** If you're using [auto-discovery](~/usage/resource-graph.md#auto-discovery), this happens automatically.

```c#
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddResourceDefinition<ArticleDefinition>();
}
}
```

**Note:** Prior to the introduction of auto-discovery (in v3), you needed to register the
`ResourceDefinition` on the container yourself:
resource definition on the container yourself:

```c#
services.AddScoped<ResourceDefinition<Product>, ProductResource>();
Expand All @@ -29,7 +42,7 @@ from Entity Framework Core `IQueryable` execution.
There are some cases where you want attributes (or relationships) conditionally excluded from your resource response.
For example, you may accept some sensitive data that should only be exposed to administrators after creation.

Note: to exclude attributes unconditionally, use `[Attr(Capabilities = ~AttrCapabilities.AllowView)]` on a resource class property.
**Note:** to exclude attributes unconditionally, use `[Attr(Capabilities = ~AttrCapabilities.AllowView)]` on a resource class property.

```c#
public class UserDefinition : JsonApiResourceDefinition<User>
Expand Down
4 changes: 2 additions & 2 deletions docs/usage/extensibility/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ public class Startup
```

In v3.0 we introduced an extension method that you can use to register a resource service on all of its JsonApiDotNetCore interfaces.
This is helpful when you implement a subset of the resource interfaces and want to register them all in one go.
This is helpful when you implement (a subset of) the resource interfaces and want to register them all in one go.

Note: If you're using service discovery, this happens automatically.
**Note:** If you're using [auto-discovery](~/usage/resource-graph.md#auto-discovery), this happens automatically.

```c#
public class Startup
Expand Down
5 changes: 2 additions & 3 deletions docs/usage/resource-graph.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# The Resource Graph

_NOTE: prior to v4 this was called the `ContextGraph`_

The `ResourceGraph` is a map of all the JSON:API resources and their relationships that your API serves.

It is built at app startup and available as a singleton through Dependency Injection.

**Note:** Prior to v4 this was called the `ContextGraph`.

## Constructing The Graph

There are three ways the resource graph can be created:
Expand Down