generated from Avanade/avanade-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCosmosDbModelContainer.cs
389 lines (347 loc) · 24 KB
/
CosmosDbModelContainer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/CoreEx
using CoreEx.Abstractions;
using CoreEx.Entities;
using CoreEx.Results;
using Microsoft.Azure.Cosmos;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace CoreEx.Cosmos.Model
{
/// <summary>
/// Provides <see cref="CosmosDb"/> model-only container.
/// </summary>
/// <typeparam name="TModel">The cosmos model <see cref="Type"/>.</typeparam>
/// <param name="cosmosDb">The <see cref="ICosmosDb"/>.</param>
/// <param name="containerId">The <see cref="Microsoft.Azure.Cosmos.Container"/> identifier.</param>
/// <param name="dbArgs">The optional <see cref="CosmosDbArgs"/>.</param>
public class CosmosDbModelContainer<TModel>(ICosmosDb cosmosDb, string containerId, CosmosDbArgs? dbArgs = null) : CosmosDbModelContainerBase<TModel, CosmosDbModelContainer<TModel>>(cosmosDb, containerId, dbArgs) where TModel : class, IEntityKey, new()
{
private Func<TModel, PartitionKey>? _partitionKey;
/// <summary>
/// Sets the function to determine the <see cref="PartitionKey"/>; used for <see cref="GetPartitionKey(TModel, CosmosDbArgs)"/> (only <b>Create</b> and <b>Update</b> operations).
/// </summary>
/// <param name="partitionKey">The function to determine the <see cref="PartitionKey"/>.</param>
/// <returns>The <see cref="CosmosDbModelContainer{TModel}"/> instance to support fluent-style method-chaining.</returns>
/// <remarks>This is used where there is a value and the corresponding <see cref="PartitionKey"/> needs to be dynamically determined.</remarks>
public CosmosDbModelContainer<TModel> UsePartitionKey(Func<TModel, PartitionKey> partitionKey)
{
_partitionKey = partitionKey;
return this;
}
/// <summary>
/// Gets the <see cref="PartitionKey"/> from the <paramref name="model"/> (only <b>Create</b> and <b>Update</b> operations).
/// </summary>
/// <param name="model">The model to infer <see cref="PartitionKey"/> from.</param>
/// <param name="dbArgs">The <see cref="CosmosDbArgs"/>.</param>
/// <returns>The <see cref="PartitionKey"/>.</returns>
/// <exception cref="AuthorizationException">Will be thrown where the infered <see cref="PartitionKey"/> is not equal to <see cref="CosmosDbContainer.DbArgs"/> (where not <c>null</c>).</exception>
public PartitionKey GetPartitionKey(TModel model, CosmosDbArgs dbArgs)
{
var dbpk = DbArgs.PartitionKey;
var pk = _partitionKey?.Invoke(model) ?? dbArgs.PartitionKey ?? DbArgs.PartitionKey ?? PartitionKey.None;
if (dbpk is not null && dbpk != PartitionKey.None && dbpk != pk)
throw new AuthorizationException();
return pk;
}
/// <summary>
/// Gets the <b>CosmosDb</b> identifier from the <paramref name="model"/> <see cref="IEntityKey.EntityKey"/>.
/// </summary>
/// <param name="model">The model value.</param>
/// <returns>The <b>CosmosDb</b> identifier.</returns>
public string GetCosmosId(TModel model) => GetCosmosId(model.ThrowIfNull(nameof(model)).EntityKey);
/// <summary>
/// Gets the <b>value</b> from the response updating any special properties as required.
/// </summary>
/// <param name="resp">The response value.</param>
/// <returns>The entity value.</returns>
internal static TModel? GetResponseValue(Response<TModel> resp) => resp?.Resource == null ? default : resp.Resource;
/// <inheritdoc/>
protected override bool IsModelValid(object? model, CosmosDbArgs args, bool checkAuthorized) => IsModelValid((TModel?)model, args, checkAuthorized);
/// <summary>
/// Checks whether the <paramref name="model"/> is in a valid state for the operation.
/// </summary>
/// <param name="model">The model value.</param>
/// <param name="args">The specific <see cref="CosmosDbArgs"/> for the operation.</param>
/// <param name="checkAuthorized">Indicates whether an additional authorization check should be performed against the <paramref name="model"/>.</param>
/// <returns><c>true</c> indicates that the model is in a valid state; otherwise, <c>false</c>.</returns>
public bool IsModelValid(TModel? model, CosmosDbArgs args, bool checkAuthorized)
=> !(model == null
|| (args.FilterByTenantId && model is ITenantId tenantId && tenantId.TenantId != args.GetTenantId())
|| (model is ILogicallyDeleted ld && ld.IsDeleted.HasValue && ld.IsDeleted.Value)
|| (checkAuthorized && IsAuthorized(model).IsFailure));
/// <summary>
/// Checks the value to determine whether the user is authorized with the <see cref="CosmosDb.GetAuthorizeFilter{TModel}(string)"/>.
/// </summary>
/// <param name="model">The model value.</param>
/// <remarks>Either <see cref="Result.Success"/> or <see cref="Result.AuthorizationError"/>.</remarks>
public Result IsAuthorized(TModel model)
{
if (model != default)
{
var filter = CosmosDb.GetAuthorizeFilter<TModel>(Container.Id);
if (filter != null && !((IQueryable<TModel>)filter(new TModel[] { model }.AsQueryable())).Any())
return Result.AuthorizationError();
}
return Result.Success;
}
/// <summary>
/// Gets (creates) a <see cref="CosmosDbQuery{T, TModel}"/> to enable LINQ-style queries.
/// </summary>
/// <param name="query">The function to perform additional query execution.</param>
/// <returns>The <see cref="CosmosDbQuery{T, TModel}"/>.</returns>
public CosmosDbModelQuery<TModel> Query(Func<IQueryable<TModel>, IQueryable<TModel>>? query) => Query(new CosmosDbArgs(DbArgs), query);
/// <summary>
/// Gets (creates) a <see cref="CosmosDbQuery{T, TModel}"/> to enable LINQ-style queries.
/// </summary>
/// <param name="partitionKey">The <see cref="PartitionKey"/>.</param>
/// <param name="query">The function to perform additional query execution.</param>
/// <returns>The <see cref="CosmosDbQuery{T, TModel}"/>.</returns>
public CosmosDbModelQuery<TModel> Query(PartitionKey? partitionKey = null, Func<IQueryable<TModel>, IQueryable<TModel>>? query = null) => Query(new CosmosDbArgs(DbArgs, partitionKey), query);
/// <summary>
/// Gets (creates) a <see cref="CosmosDbQuery{T, TModel}"/> to enable LINQ-style queries.
/// </summary>
/// <param name="dbArgs">The <see cref="CosmosDbArgs"/>.</param>
/// <param name="query">The function to perform additional query execution.</param>
/// <returns>The <see cref="CosmosDbQuery{T, TModel}"/>.</returns>
public CosmosDbModelQuery<TModel> Query(CosmosDbArgs dbArgs, Func<IQueryable<TModel>, IQueryable<TModel>>? query = null) => new(this, dbArgs, query);
/// <summary>
/// Gets the model for the specified <paramref name="key"/>.
/// </summary>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The model value where found; otherwise, <c>null</c> (see <see cref="CosmosDbArgs.NullOnNotFound"/>).</returns>
public async Task<TModel?> GetAsync(CompositeKey key, CancellationToken cancellationToken = default) => await GetWithResultAsync(key, cancellationToken);
/// <summary>
/// Gets the model for the specified <paramref name="key"/> with a <see cref="Result{T}"/>.
/// </summary>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The model value where found; otherwise, <c>null</c> (see <see cref="CosmosDbArgs.NullOnNotFound"/>).</returns>
public Task<Result<TModel?>> GetWithResultAsync(CompositeKey key, CancellationToken cancellationToken = default) => GetWithResultAsync(new CosmosDbArgs(DbArgs), key, cancellationToken);
/// <summary>
/// Gets the model for the specified <paramref name="key"/>.
/// </summary>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="partitionKey">The <see cref="PartitionKey"/>. Defaults to <see cref="CosmosDbContainer.DbArgs"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The model value where found; otherwise, <c>null</c> (see <see cref="CosmosDbArgs.NullOnNotFound"/>).</returns>
public async Task<TModel?> GetAsync(CompositeKey key, PartitionKey? partitionKey, CancellationToken cancellationToken = default) => await GetWithResultAsync(key, partitionKey, cancellationToken).ConfigureAwait(false);
/// <summary>
/// Gets the model for the specified <paramref name="key"/> with a <see cref="Result{T}"/>.
/// </summary>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="partitionKey">The <see cref="PartitionKey"/>. Defaults to <see cref="CosmosDbContainer.DbArgs"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The model value where found; otherwise, <c>null</c> (see <see cref="CosmosDbArgs.NullOnNotFound"/>).</returns>
public Task<Result<TModel?>> GetWithResultAsync(CompositeKey key, PartitionKey? partitionKey, CancellationToken cancellationToken = default) => GetWithResultAsync(new CosmosDbArgs(DbArgs, partitionKey), key, cancellationToken);
/// <summary>
/// Gets the model for the specified <paramref name="key"/>.
/// </summary>
/// <param name="dbArgs">The <see cref="CosmosDbArgs"/>.</param>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The model value where found; otherwise, <c>null</c> (see <see cref="CosmosDbArgs.NullOnNotFound"/>).</returns>
public async Task<TModel?> GetAsync(CosmosDbArgs dbArgs, CompositeKey key, CancellationToken cancellationToken = default) => (await GetWithResultAsync(dbArgs, key, cancellationToken).ConfigureAwait(false)).Value;
/// <summary>
/// Gets the model for the specified <paramref name="key"/> with a <see cref="Result{T}"/>.
/// </summary>
/// <param name="dbArgs">The <see cref="CosmosDbArgs"/>.</param>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The model value where found; otherwise, <c>null</c> (see <see cref="CosmosDbArgs.NullOnNotFound"/>).</returns>
public Task<Result<TModel?>> GetWithResultAsync(CosmosDbArgs dbArgs, CompositeKey key, CancellationToken cancellationToken = default) => CosmosDb.Invoker.InvokeAsync(CosmosDb, GetCosmosId(key), dbArgs, async (_, id, args, ct) =>
{
try
{
var pk = args.PartitionKey ?? DbArgs.PartitionKey ?? PartitionKey.None;
var resp = await Container.ReadItemAsync<TModel>(id, pk, args.GetItemRequestOptions(), ct).ConfigureAwait(false);
if (!IsModelValid(resp.Resource, args, false))
return args.NullOnNotFound ? Result<TModel?>.None : Result<TModel?>.NotFoundError();
return Result.Go(IsAuthorized(resp)).ThenAs(() => GetResponseValue(resp));
}
catch (CosmosException dcex) when (args.NullOnNotFound && dcex.StatusCode == System.Net.HttpStatusCode.NotFound) { return args.NullOnNotFound ? Result<TModel?>.None : Result<TModel?>.NotFoundError(); }
}, cancellationToken, nameof(GetWithResultAsync));
/// <summary>
/// Creates the model.
/// </summary>
/// <param name="model">The model to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The created model.</returns>
public async Task<TModel> CreateAsync(TModel model, CancellationToken cancellationToken = default) => await CreateWithResultAsync(model, cancellationToken).ConfigureAwait(false);
/// <summary>
/// Creates the model with a <see cref="Result{T}"/>.
/// </summary>
/// <param name="model">The model to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The created model.</returns>
public Task<Result<TModel>> CreateWithResultAsync(TModel model, CancellationToken cancellationToken = default) => CreateWithResultAsync(new CosmosDbArgs(DbArgs), model, cancellationToken);
/// <summary>
/// Creates the model.
/// </summary>
/// <param name="dbArgs">The <see cref="CosmosDbArgs"/>.</param>
/// <param name="model">The model to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The created model.</returns>
public async Task<TModel> CreateAsync(CosmosDbArgs dbArgs, TModel model, CancellationToken cancellationToken = default) => (await CreateWithResultAsync(dbArgs, model, cancellationToken).ConfigureAwait(false)).Value;
/// <summary>
/// Creates the model with a <see cref="Result{T}"/>.
/// </summary>
/// <param name="dbArgs">The <see cref="CosmosDbArgs"/>.</param>
/// <param name="model">The model to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The created model.</returns>
public Task<Result<TModel>> CreateWithResultAsync(CosmosDbArgs dbArgs, TModel model, CancellationToken cancellationToken = default) => CosmosDb.Invoker.InvokeAsync(CosmosDb, model.ThrowIfNull(nameof(model)), dbArgs, async (_, m, args, ct) =>
{
Cleaner.ResetTenantId(m);
var pk = GetPartitionKey(model, dbArgs);
return await Result
.Go(IsAuthorized(model))
.ThenAsAsync(() => Container.CreateItemAsync(model, pk, args.GetItemRequestOptions(), ct))
.ThenAs(resp => GetResponseValue(resp!)!);
}, cancellationToken, nameof(CreateWithResultAsync));
/// <summary>
/// Updates the model.
/// </summary>
/// <param name="model">The model to update.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The updated model.</returns>
public async Task<TModel> UpdateAsync(TModel model, CancellationToken cancellationToken = default) => await UpdateWithResultAsync(model, cancellationToken).ConfigureAwait(false);
/// <summary>
/// Updates the model with a <see cref="Result{T}"/>.
/// </summary>
/// <param name="model">The model to update.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The updated model.</returns>
public Task<Result<TModel>> UpdateWithResultAsync(TModel model, CancellationToken cancellationToken = default) => UpdateWithResultAsync(new CosmosDbArgs(DbArgs), model, cancellationToken);
/// <summary>
/// Updates the model.
/// </summary>
/// <param name="dbArgs">The <see cref="CosmosDbArgs"/>.</param>
/// <param name="model">The model to update.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The updated model.</returns>
public async Task<TModel> UpdateAsync(CosmosDbArgs dbArgs, TModel model, CancellationToken cancellationToken = default) => (await UpdateWithResultAsync(dbArgs, model, cancellationToken).ConfigureAwait(false)).Value;
/// <summary>
/// Updates the model with a <see cref="Result{T}"/>.
/// </summary>
/// <param name="dbArgs">The <see cref="CosmosDbArgs"/>.</param>
/// <param name="model">The model to update.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The updated model.</returns>
public Task<Result<TModel>> UpdateWithResultAsync(CosmosDbArgs dbArgs, TModel model, CancellationToken cancellationToken = default) => UpdateWithResultInternalAsync(dbArgs, model, null, cancellationToken);
/// <summary>
/// Updates the model with a <see cref="Result{T}"/> (internal).
/// </summary>
/// <param name="dbArgs">The <see cref="CosmosDbArgs"/>.</param>
/// <param name="model">The model to update.</param>
/// <param name="modelUpdater">The action to update the model after the read.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The updated model.</returns>
internal Task<Result<TModel>> UpdateWithResultInternalAsync(CosmosDbArgs dbArgs, TModel model, Action<TModel>? modelUpdater, CancellationToken cancellationToken) => CosmosDb.Invoker.InvokeAsync(CosmosDb, model.ThrowIfNull(nameof(model)), dbArgs, async (_, m, args, ct) =>
{
// Where supporting etag then use IfMatch for concurrency.
var ro = args.GetItemRequestOptions();
if (ro.IfMatchEtag == null && m is IETag etag && etag.ETag != null)
ro.IfMatchEtag = ETagGenerator.FormatETag(etag.ETag);
// Must read existing to update.
var id = GetCosmosId(m);
var pk = GetPartitionKey(model, dbArgs);
var resp = await Container.ReadItemAsync<TModel>(id, pk, ro, ct).ConfigureAwait(false);
if (!IsModelValid(resp.Resource, args, false))
return Result<TModel>.NotFoundError();
return await Result
.Go(IsAuthorized(resp))
.When(() => m is IETag etag2 && etag2.ETag != null && ETagGenerator.FormatETag(etag2.ETag) != resp.ETag, () => Result.ConcurrencyError())
.Then(() =>
{
ro.SessionToken = resp.Headers?.Session;
modelUpdater?.Invoke(resp.Resource);
Cleaner.ResetTenantId(resp.Resource);
// Re-check auth to make sure not updating to something not allowed.
return IsAuthorized(resp);
})
.ThenAsAsync(async () =>
{
resp = await Container.ReplaceItemAsync(resp.Resource, id, pk, ro, ct).ConfigureAwait(false);
return GetResponseValue(resp)!;
});
}, cancellationToken, nameof(UpdateWithResultAsync));
/// <summary>
/// Deletes the model for the specified <paramref name="key"/>.
/// </summary>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
public async Task DeleteAsync(CompositeKey key, CancellationToken cancellationToken = default) => (await DeleteWithResultAsync(key, cancellationToken).ConfigureAwait(false)).ThrowOnError();
/// <summary>
/// Deletes the model for the specified <paramref name="key"/> with a <see cref="Result"/>.
/// </summary>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
public Task<Result> DeleteWithResultAsync(CompositeKey key, CancellationToken cancellationToken = default) => DeleteWithResultAsync(new CosmosDbArgs(DbArgs), key, cancellationToken);
/// <summary>
/// Deletes the model for the specified <paramref name="key"/>.
/// </summary>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="partitionKey">The <see cref="PartitionKey"/>. Defaults to <see cref="CosmosDbContainer.DbArgs"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
public async Task DeleteAsync(CompositeKey key, PartitionKey? partitionKey, CancellationToken cancellationToken = default) => (await DeleteWithResultAsync(key, partitionKey, cancellationToken).ConfigureAwait(false)).ThrowOnError();
/// <summary>
/// Deletes the model for the specified <paramref name="key"/> with a <see cref="Result"/>.
/// </summary>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="partitionKey">The <see cref="PartitionKey"/>. Defaults to <see cref="CosmosDbContainer.DbArgs"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
public Task<Result> DeleteWithResultAsync(CompositeKey key, PartitionKey? partitionKey, CancellationToken cancellationToken = default) => DeleteWithResultAsync(new CosmosDbArgs(DbArgs, partitionKey), key, cancellationToken);
/// <summary>
/// Deletes the model for the specified <paramref name="key"/> with a <see cref="Result"/>.
/// </summary>
/// <param name="dbArgs">The <see cref="CosmosDbArgs"/>.</param>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
public async Task<Result> DeleteAsync(CosmosDbArgs dbArgs, CompositeKey key, CancellationToken cancellationToken = default) => (await DeleteWithResultAsync(dbArgs, key, cancellationToken).ConfigureAwait(false)).ThrowOnError();
/// <summary>
/// Deletes the model for the specified <paramref name="key"/> with a <see cref="Result"/>.
/// </summary>
/// <param name="dbArgs">The <see cref="CosmosDbArgs"/>.</param>
/// <param name="key">The <see cref="CompositeKey"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
public Task<Result> DeleteWithResultAsync(CosmosDbArgs dbArgs, CompositeKey key, CancellationToken cancellationToken = default) => CosmosDb.Invoker.InvokeAsync(CosmosDb, GetCosmosId(key), dbArgs, async (_, id, args, ct) =>
{
try
{
// Must read the existing to validate.
var ro = args.GetItemRequestOptions();
var pk = args.PartitionKey ?? DbArgs.PartitionKey ?? PartitionKey.None;
var resp = await Container.ReadItemAsync<TModel>(id, pk, ro, ct).ConfigureAwait(false);
if (!IsModelValid(resp.Resource, args, false))
return Result.Success;
// Delete; either logically or physically.
if (resp.Resource is ILogicallyDeleted ild)
{
if (ild.IsDeleted.HasValue && ild.IsDeleted.Value)
return Result.Success;
ild.IsDeleted = true;
return await Result
.Go(IsAuthorized(resp.Resource))
.ThenAsync(async () =>
{
ro.SessionToken = resp.Headers?.Session;
await Container.ReplaceItemAsync(resp.Resource, id, pk, ro, ct).ConfigureAwait(false);
return Result.Success;
});
}
return await Result
.Go(IsAuthorized(resp.Resource))
.ThenAsync(async () =>
{
ro.SessionToken = resp.Headers?.Session;
await Container.DeleteItemAsync<TModel>(id, pk, ro, ct).ConfigureAwait(false);
return Result.Success;
});
}
catch (CosmosException cex) when (cex.StatusCode == System.Net.HttpStatusCode.NotFound) { return Result.NotFoundError(); }
}, cancellationToken, nameof(DeleteWithResultAsync));
}
}