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
* Generic resource definitions
Made resource definitions a first-class pluggable extensibility point, similar to resource services and repositories. So developers now can derive from JsonApiResourceDefinition, implement IResourceDefinition, or insert base classes in the type hierarchy to share common logic. Such a base class can then be registered as an open generic, so that all resources will use that (unless the container finds a non-generic class, which is a better match) instead of the built-in JsonApiResourceDefinition.
To accomplish this, I had to split up ResourceDefinition into two:
- JsonApiResourceDefinition is highly pluggable like described above
- ResourceHooksDefinition contains just the hook callbacks
This way, the recursive resolve logic for resource hooks remains as-is. Since it did not use IResourceDefinitionProvider, that type has been replaced with IResourceDefinitionAccessor, which invokes the requested callbacks directly on the found class. What used to be IResourceDefinition (an intermediate type to invoke callbacks on) no longer exists.
* Only scan for hooks when enabled in options
Replaced IHasMeta with IResourceDefinition method
* Fix broken cibuild
* Review feedback
* Made ResourceDefinitionAccessor.GetResourceDefinition protected
* Renamed IRequestMeta to IResponseMeta; updated documentation
* quotes
* Review feedback
Copy file name to clipboardExpand all lines: docs/usage/meta.md
+32-18
Original file line number
Diff line number
Diff line change
@@ -1,43 +1,60 @@
1
1
# Metadata
2
2
3
-
Non-standard metadata can be added to your API responses in two ways: Resource and Request Meta. In the event of a key collision, the Request Meta will take precendence.
3
+
Top-level metadata can be added to your API responses in two ways: globally and per resource type. In the event of a key collision, the resource meta will take precendence.
4
4
5
-
## Resource Meta
5
+
## Global Meta
6
6
7
-
Resource Meta is metadata defined on the resource itself by implementing the `IHasMeta` interface.
7
+
Global metadata can be added by registering a service that implements `IResponseMeta`.
8
+
This is useful if you need access to other registered services to build the meta object.
8
9
9
10
```c#
10
-
publicclassPerson : Identifiable, IHasMeta
11
+
publicclassResponseMetaService : IResponseMeta
11
12
{
13
+
publicResponseMetaService(/*...other dependencies here */) {
14
+
// ...
15
+
}
16
+
12
17
publicDictionary<string, object> GetMeta()
13
18
{
14
19
returnnewDictionary<string, object>
15
20
{
16
21
{"copyright", "Copyright 2018 Example Corp."},
17
-
{"authors", new[] {"John Doe"}}
22
+
{"authors", newstring[] {"John Doe"}}
18
23
};
19
24
}
20
25
}
21
26
```
22
27
23
-
## Request Meta
28
+
```json
29
+
{
30
+
"meta": {
31
+
"copyright": "Copyright 2018 Example Corp.",
32
+
"authors": [
33
+
"John Doe"
34
+
]
35
+
},
36
+
"data": {
37
+
// ...
38
+
}
39
+
}
40
+
```
24
41
25
-
Request Meta can be added by injecting a service that implements `IRequestMeta`.
26
-
This is useful if you need access to other injected services to build the meta object.
42
+
## Resource Meta
43
+
44
+
Resource-specific metadata can be added by implementing `IResourceDefinition<TResource, TId>.GetMeta` (or overriding it on `JsonApiResourceDefinition`):
0 commit comments