You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because we copy resource properties into an intermediate object before serialization, Newtonsoft.Json annotations on properties are ignored.
94
99
100
+
95
101
## Enable ModelState Validation
96
102
97
103
If you would like to use ASP.NET Core ModelState validation into your controllers when creating / updating resources, set `ValidateModelState = true`. By default, no model validation is performed.
Copy file name to clipboardExpand all lines: docs/usage/resource-graph.md
+26-12Lines changed: 26 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,10 +14,14 @@ There are three ways the resource graph can be created:
14
14
2. Specifying an entire DbContext
15
15
3. Manually specifying each resource
16
16
17
-
### Auto-Discovery
17
+
It is also possible to combine the three of them at once. Be aware that some configuration might overlap,
18
+
for example one could manually add a resource to the graph which is also auto-discovered. In such a scenario, the configuration
19
+
is prioritized by the list above in descending order.
20
+
21
+
### Auto-discovery
18
22
19
23
Auto-discovery refers to the process of reflecting on an assembly and
20
-
detecting all of the json:api resources and services.
24
+
detecting all of the json:api resources, resource definitions, resource services and repositories.
21
25
22
26
The following command will build the resource graph using all `IIdentifiable`
23
27
implementations. It also injects resource definitions and service layer overrides which we will
@@ -34,9 +38,9 @@ public void ConfigureServices(IServiceCollection services)
34
38
}
35
39
```
36
40
37
-
### Entity Framework Core DbContext
41
+
### Specifying an Entity Framework Core DbContext
38
42
39
-
If you are using Entity Framework Core as your ORM, you can add an entire `DbContext`with one line.
43
+
If you are using Entity Framework Core as your ORM, you can add all the models of a `DbContext` to the resource graph.
40
44
41
45
```c#
42
46
// Startup.cs
@@ -46,7 +50,7 @@ public void ConfigureServices(IServiceCollection services)
46
50
}
47
51
```
48
52
49
-
Be aware that the previous command does not inject resource definitions and service layer overrides. You can combine it with auto-discovery to register them.
53
+
Be aware that this does not register resource definitions, resource services and repositories. You can combine it with auto-discovery to achieve this.
50
54
51
55
```c#
52
56
// Startup.cs
@@ -60,31 +64,41 @@ public void ConfigureServices(IServiceCollection services)
The public resource name is exposed through the `type` member in the json:api payload. This can be configured by the following approaches (in order of priority):
77
83
78
-
The public resource type name is determined by the following criteria (in order of priority):
84
+
1. The `publicName` parameter when manually adding a resource to the graph
85
+
```c#
86
+
services.AddJsonApi(resources: builder=>
87
+
{
88
+
builder.Add<Person>(publicName: "people");
89
+
});
90
+
```
79
91
80
-
1. The model is decorated with a `ResourceAttribute`
92
+
2. The model is decorated with a `ResourceAttribute`
81
93
```c#
82
-
[Resource("my-models")]
94
+
[Resource("myResources")]
83
95
publicclassMyModel : Identifiable { /* ... */ }
84
96
```
85
97
86
-
2. The configured naming convention (by default this is camel-case).
98
+
3. The configured naming convention (by default this is camel-case).
87
99
```c#
88
100
// this will be registered as "myModels"
89
101
publicclassMyModel : Identifiable { /* ... */ }
90
102
```
103
+
104
+
The default naming convention can be changed in [options](./options.md#custom-serializer-settings).
@@ -20,40 +12,47 @@ public void ConfigureServices(IServiceCollection services)
20
12
```
21
13
Which results in URLs like: https://yourdomain.com/api/v1/people
22
14
23
-
## Disable Convention
15
+
## Default Routing Convention
24
16
25
-
You can disable the default casing convention and specify your own template by using the `DisableRoutingConvention` attribute.
17
+
The library will configure routes for all controllers in your project. By default, routes are camel-cased. This is based on the [recommendations](https://jsonapi.org/recommendations/) outlined in the json:api spec.
It is important to note that your routes must still end with the model name in the same format as the resource name. This is so that we can build accurate resource links in the json:api document. For example, if you define a resource as MyModels, the controller route must match.
29
+
The public name of the resource ([which can be customized](./resource-graph.md#public-resource-name)) is used for the route, instead of the controller name.
42
30
31
+
### Non-json:api controllers
32
+
33
+
If a controller does not inherit from `JsonApiController<TResource>`, the [configured naming convention](./options.md#custom-serializer-settings) is applied to the name of the controller.
It is required to match your custom url with the public name of the associated resource.
49
+
50
+
## Advanced Usage: Custom Routing Convention
57
51
58
-
See [this](~/usage/resource-graph.md#public-resource-type-name) for
59
-
more information on how the resource name is determined.
52
+
It is possible to replace the built-in routing convention with a [custom routing convention]](https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/application-model?view=aspnetcore-3.1#sample-custom-routing-convention) by registering an implementation of `IJsonApiRoutingConvention`.
0 commit comments