|
1 | 1 | using System.Collections.Generic;
|
2 | 2 | using System.Linq;
|
| 3 | +using System.Threading; |
| 4 | +using System.Threading.Tasks; |
3 | 5 | using JetBrains.Annotations;
|
4 | 6 | using JsonApiDotNetCore.Queries.Expressions;
|
5 | 7 |
|
@@ -29,6 +31,7 @@ public interface IResourceDefinition<TResource> : IResourceDefinition<TResource,
|
29 | 31 | /// The resource identifier type.
|
30 | 32 | /// </typeparam>
|
31 | 33 | [PublicAPI]
|
| 34 | + // ReSharper disable once TypeParameterCanBeVariant -- Justification: making TId contravariant is a breaking change. |
32 | 35 | public interface IResourceDefinition<TResource, TId>
|
33 | 36 | where TResource : class, IIdentifiable<TId>
|
34 | 37 | {
|
@@ -129,5 +132,106 @@ public interface IResourceDefinition<TResource, TId>
|
129 | 132 | /// Enables to add JSON:API meta information, specific to this resource.
|
130 | 133 | /// </summary>
|
131 | 134 | IDictionary<string, object> GetMeta(TResource resource);
|
| 135 | + |
| 136 | + /// <summary> |
| 137 | + /// Enables to execute custom logic to initialize a newly instantiated resource during a POST request. This is typically used to assign default values to |
| 138 | + /// properties or to side-load-and-attach required relationships. |
| 139 | + /// </summary> |
| 140 | + /// <param name="resource"> |
| 141 | + /// A freshly instantiated resource object. |
| 142 | + /// </param> |
| 143 | + /// <param name="cancellationToken"> |
| 144 | + /// Propagates notification that request handling should be canceled. |
| 145 | + /// </param> |
| 146 | + Task OnInitializeResourceAsync(TResource resource, CancellationToken cancellationToken); |
| 147 | + |
| 148 | + /// <summary> |
| 149 | + /// Enables to execute custom logic, just before a resource is inserted in the underlying data store, during a POST request. This is typically used to |
| 150 | + /// overwrite attributes from the incoming request, such as a creation-timestamp. Another use case is to add a notification message to an outbox table, |
| 151 | + /// which gets committed along with the resource write in a single transaction (see https://microservices.io/patterns/data/transactional-outbox.html). |
| 152 | + /// </summary> |
| 153 | + /// <param name="resource"> |
| 154 | + /// The resource with incoming request data applied on it. |
| 155 | + /// </param> |
| 156 | + /// <param name="cancellationToken"> |
| 157 | + /// Propagates notification that request handling should be canceled. |
| 158 | + /// </param> |
| 159 | + Task OnBeforeCreateResourceAsync(TResource resource, CancellationToken cancellationToken); |
| 160 | + |
| 161 | + /// <summary> |
| 162 | + /// Enables to execute custom logic after a resource has been inserted in the underlying data store, during a POST request. A typical use case is to |
| 163 | + /// enqueue a notification message on a service bus. |
| 164 | + /// </summary> |
| 165 | + /// <param name="resource"> |
| 166 | + /// The re-fetched resource after a successful insertion. |
| 167 | + /// </param> |
| 168 | + /// <param name="cancellationToken"> |
| 169 | + /// Propagates notification that request handling should be canceled. |
| 170 | + /// </param> |
| 171 | + Task OnAfterCreateResourceAsync(TResource resource, CancellationToken cancellationToken); |
| 172 | + |
| 173 | + /// <summary> |
| 174 | + /// Enables to execute custom logic to validate if the update request can be processed, based on the currently stored resource. A typical use case is to |
| 175 | + /// throw when the resource is soft-deleted or archived. |
| 176 | + /// </summary> |
| 177 | + /// <param name="resource"> |
| 178 | + /// The resource as currently stored in the underlying data store. |
| 179 | + /// </param> |
| 180 | + /// <param name="cancellationToken"> |
| 181 | + /// Propagates notification that request handling should be canceled. |
| 182 | + /// </param> |
| 183 | + Task OnAfterGetForUpdateResourceAsync(TResource resource, CancellationToken cancellationToken); |
| 184 | + |
| 185 | + /// <summary> |
| 186 | + /// Enables to execute custom logic, just before a resource is updated in the underlying data store, during a PATCH request. This is typically used to |
| 187 | + /// overwrite attributes from the incoming request, such as a last-modification-timestamp. Another use case is to add a notification message to an outbox |
| 188 | + /// table, which gets committed along with the resource write in a single transaction (see |
| 189 | + /// https://microservices.io/patterns/data/transactional-outbox.html). |
| 190 | + /// </summary> |
| 191 | + /// <param name="resource"> |
| 192 | + /// The stored resource with incoming request data applied on it. |
| 193 | + /// </param> |
| 194 | + /// <param name="cancellationToken"> |
| 195 | + /// Propagates notification that request handling should be canceled. |
| 196 | + /// </param> |
| 197 | + Task OnBeforeUpdateResourceAsync(TResource resource, CancellationToken cancellationToken); |
| 198 | + |
| 199 | + /// <summary> |
| 200 | + /// Enables to execute custom logic after a resource has been updated in the underlying data store, during a PATCH request. A typical use case is to |
| 201 | + /// enqueue a notification message on a service bus. |
| 202 | + /// </summary> |
| 203 | + /// <param name="resource"> |
| 204 | + /// The re-fetched resource after a successful update. |
| 205 | + /// </param> |
| 206 | + /// <param name="cancellationToken"> |
| 207 | + /// Propagates notification that request handling should be canceled. |
| 208 | + /// </param> |
| 209 | + Task OnAfterUpdateResourceAsync(TResource resource, CancellationToken cancellationToken); |
| 210 | + |
| 211 | + /// <summary> |
| 212 | + /// Enables to execute custom logic, just before a resource is deleted from the underlying data store, during a DELETE request. This enables to throw in |
| 213 | + /// case the user does not have permission, an attempt is made to delete an unarchived resource or a non-closed work item etc. Another use case is to add |
| 214 | + /// a notification message to an outbox table, which gets committed along with the resource write in a single transaction (see |
| 215 | + /// https://microservices.io/patterns/data/transactional-outbox.html). |
| 216 | + /// </summary> |
| 217 | + /// <param name="id"> |
| 218 | + /// The identifier of the resource to delete. |
| 219 | + /// </param> |
| 220 | + /// <param name="cancellationToken"> |
| 221 | + /// Propagates notification that request handling should be canceled. |
| 222 | + /// </param> |
| 223 | + Task OnBeforeDeleteResourceAsync(TId id, CancellationToken cancellationToken); |
| 224 | + |
| 225 | + /// <summary> |
| 226 | + /// Enables to execute custom logic after a resource has been deleted from the underlying data store, during a DELETE request. A typical use case is to |
| 227 | + /// enqueue a notification message on a service bus. |
| 228 | + /// </summary> |
| 229 | + /// <param name="id"> |
| 230 | + /// The identifier of the resource to delete. |
| 231 | + /// </param> |
| 232 | + /// <param name="cancellationToken"> |
| 233 | + /// Propagates notification that request handling should be canceled. |
| 234 | + /// </param> |
| 235 | + Task OnAfterDeleteResourceAsync(TId id, CancellationToken cancellationToken); |
132 | 236 | }
|
133 | 237 | }
|
0 commit comments