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
It is also possible to directly access the .NET Core `MvcOptions` object and have full controll over which components are registered.
42
+
It is also possible to directly access the .NET Core `MvcOptions` object and have full control over which components are registered.
43
43
44
44
## Configuring MvcOptions
45
45
46
-
JsonApiDotNetCore internally configures `MvcOptions` when calling `AddJsonApi( ... )`. However, it is still possible to register a custom configuration callback. To achieve this it is recommended to register this callback *after* the `AddJsonApi( ... )` call. It is also possible to do it earlier, but your configuration might be overridden by the JsonApiDotNetCore configuration.
46
+
JsonApiDotNetCore internally configures `MvcOptions` when calling `AddJsonApi( ... )`. However, it is still possible to register a custom configuration callback. To achieve this it is recommended to register this callback *after* the `AddJsonApi( ... )` call. It is also possible to do it earlier, but your configuration might be overwritten by the JsonApiDotNetCore configuration.
47
47
48
48
The following example replaces all internally registered filters by retrieving a custom filter from the DI container.
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
+5-18
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ public void ConfigureServices(IServiceCollection services)
28
28
{
29
29
services.AddJsonApi(resources: builder=>
30
30
{
31
-
builder.AddResource<Person>();
31
+
builder.Add<Person>();
32
32
});
33
33
}
34
34
```
@@ -60,7 +60,7 @@ public void ConfigureServices(IServiceCollection services)
60
60
### Auto-discovery
61
61
62
62
Auto-discovery refers to the process of reflecting on an assembly and
63
-
detecting all of the json:api resources and services.
63
+
detecting all of the json:api resources, resource definitions, resource services and repositories.
64
64
65
65
The following command will build the resource graph using all `IIdentifiable`
66
66
implementations. It also injects resource definitions and service layer overrides which we will
@@ -81,11 +81,11 @@ public void ConfigureServices(IServiceCollection services)
81
81
82
82
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):
83
83
84
-
1. The `publicName`option when manually adding a resource to the graph
84
+
1. The `publicName`parameter when manually adding a resource to the graph
This convention can be changed by setting the `SerializerSettings.ContractResolver` property on `IJsonApiOptions`. See the [options documentation](./options.md#custom-serializer-settings).
Which results in URLs like: https://yourdomain.com/api/v1/people
14
+
15
+
## Customizing Routes
16
+
2
17
The library will configure routes for each controller. By default, based on the [recommendations](https://jsonapi.org/recommendations/) outlined in the json:api spec, routes are camel-cased.
3
18
4
19
```http
5
20
GET /api/compoundModels HTTP/1.1
6
21
```
7
22
8
-
There are two ways the library will try to create a route for a controller:
9
-
1.**By inspecting the controller for an associated resource**. The library will try to first use the public resource name of the resource associated to a controller. This means that the value of the `type` member of the json:api document for a resource will be equal to the route.
10
-
Note that this implies that it is possible to configure a route configuring the exposed resource name. See [this section](~/usage/resource-graph.md#public-resource-name) on how this can be achieved. Example:
11
-
```c#
12
-
// controller
13
-
publicclassMyResourceController : JsonApiController<MyApiResource> { /* .... */ } // note that the route is NOT "myResources", but "myApiResources"
23
+
1.**Using the public name of the resource associated to a controller**.
- is `/myApiResources`, which matches the public resouce name in the json:api payload (`{ "type": "myApiResources", ... }`)
30
+
- can be configured by configuring the public resource name. See [this section](~/usage/resource-graph.md#public-resource-name) on how to do that.
17
31
18
-
// response
19
-
HTTP/1.1200OK
20
-
Content-Type:application/vnd.api+json
21
32
22
-
{
23
-
"data": [{
24
-
"type":"myApiResources",
25
-
"id":"1",
26
-
"attributes": { ... }
27
-
}]
28
-
}
29
-
```
30
-
2.**By using the name of the controller**. If no associated resource was detected for a controller, the library will construct a route from the name of the controller by using the configured naming strategy (*camelCase* by default, see [this section](~/usage/resource-graph.md#public-resource-name) on how to configure this). This is in alignment with the default .NET Core MVC routing approach.
31
-
In the following example the controller is not associated to a resource by the library because it does not inherit from `BaseJsonApiController<T>`.
33
+
2.**Using the controller name**.
34
+
If a controller does not have an associated resource, the name of the controller will be used following the configured naming strategy.
Which results in URLs like: https://yourdomain.com/api/v1/people
61
-
62
50
## Disabling the Default Routing Convention
63
51
It is possible to completely bypass the default routing convention for a particular controller and specify a custom routing template by using the `DisableRoutingConvention` attribute.
64
52
In the following example, the `CamelCasedModel` resource can be accessed on `/my-custom-route`.
0 commit comments