Skip to content

Commit 3aa68b4

Browse files
author
Bart Koelman
authored
Clarified when/how to register resource definitions (#1015)
1 parent 4364dbd commit 3aa68b4

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

docs/usage/caching.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ETag: "356075D903B8FE8D9921201A7E7CD3F9"
6060
}
6161
```
6262

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

6565
```http
6666
HEAD /articles?sort=-lastModifiedAt HTTP/1.1

docs/usage/extensibility/layer-overview.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ on your needs, you may want to replace other parts by deriving from the built-in
2323

2424
## Replacing injected services
2525

26-
**Note:** If you are using auto-discovery, then resource services, repositories and resource definitions will be automatically registered for you.
26+
**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.
2727

2828
Replacing built-in services is done on a per-resource basis and can be done through dependency injection in your Startup.cs file.
2929
For convenience, extension methods are provided to register layers on all their implemented interfaces.

docs/usage/extensibility/repositories.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ The repository should then be registered in Startup.cs.
99
public void ConfigureServices(IServiceCollection services)
1010
{
1111
services.AddScoped<IResourceRepository<Article>, ArticleRepository>();
12+
services.AddScoped<IResourceReadRepository<Article>, ArticleRepository>();
13+
services.AddScoped<IResourceWriteRepository<Article>, ArticleRepository>();
1214
}
1315
```
1416

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

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

2022
```c#
2123
public class Startup

docs/usage/extensibility/resource-definitions.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,24 @@
33
_since v2.3.4_
44

55
Resource definitions provide a resource-oriented way to handle custom business logic (irrespective of the originating endpoint).
6-
76
They are resolved from the dependency injection container, so you can inject dependencies in their constructor.
87

8+
In v4.2 we introduced an extension method that you can use to register your resource definition.
9+
10+
**Note:** If you're using [auto-discovery](~/usage/resource-graph.md#auto-discovery), this happens automatically.
11+
12+
```c#
13+
public class Startup
14+
{
15+
public void ConfigureServices(IServiceCollection services)
16+
{
17+
services.AddResourceDefinition<ArticleDefinition>();
18+
}
19+
}
20+
```
21+
922
**Note:** Prior to the introduction of auto-discovery (in v3), you needed to register the
10-
`ResourceDefinition` on the container yourself:
23+
resource definition on the container yourself:
1124

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

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

3447
```c#
3548
public class UserDefinition : JsonApiResourceDefinition<User>

docs/usage/extensibility/services.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ public class Startup
137137
```
138138

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

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

144144
```c#
145145
public class Startup

docs/usage/resource-graph.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# The Resource Graph
22

3-
_NOTE: prior to v4 this was called the `ContextGraph`_
4-
53
The `ResourceGraph` is a map of all the JSON:API resources and their relationships that your API serves.
6-
74
It is built at app startup and available as a singleton through Dependency Injection.
85

6+
**Note:** Prior to v4 this was called the `ContextGraph`.
7+
98
## Constructing The Graph
109

1110
There are three ways the resource graph can be created:

0 commit comments

Comments
 (0)