1
1
2
2
using RoyalCode . Entities ;
3
+ using RoyalCode . SmartValidations . Entities ;
3
4
using System . Diagnostics . CodeAnalysis ;
4
5
5
6
namespace RoyalCode . Repositories . Abstractions ;
@@ -17,6 +18,7 @@ namespace RoyalCode.Repositories.Abstractions;
17
18
/// </remarks>
18
19
/// <typeparam name="TEntity">The entity type.</typeparam>
19
20
public interface IAdder < in TEntity >
21
+ where TEntity : class
20
22
{
21
23
/// <summary>
22
24
/// <para>
@@ -33,6 +35,22 @@ public interface IAdder<in TEntity>
33
35
/// <param name="entity">The new entity instance.</param>
34
36
void Add ( TEntity entity ) ;
35
37
38
+ /// <summary>
39
+ /// <para>
40
+ /// Adds a new entity to the repository to be persisted.
41
+ /// </para>
42
+ /// </summary>
43
+ /// <remarks>
44
+ /// <para>
45
+ /// When implemented together with the Unit Of Work pattern the entity
46
+ /// will not be persisted directly when calling this method,
47
+ /// it will be stored in memory until the completion of the unit of work.
48
+ /// </para>
49
+ /// </remarks>
50
+ /// <param name="entity">The new entity instance.</param>
51
+ /// <param name="token">Cancellation token.</param>
52
+ ValueTask AddAsync ( TEntity entity , CancellationToken token = default ) ;
53
+
36
54
/// <summary>
37
55
/// <para>
38
56
/// Adds a collection of new entities to the repository to be persisted.
@@ -56,6 +74,7 @@ public interface IAdder<in TEntity>
56
74
/// </summary>
57
75
/// <typeparam name="TEntity">The entity type.</typeparam>
58
76
public interface IFinder < TEntity >
77
+ where TEntity : class
59
78
{
60
79
/// <summary>
61
80
/// <para>
@@ -83,6 +102,21 @@ public interface IFinder<TEntity>
83
102
/// </para>
84
103
/// </returns>
85
104
ValueTask < TEntity ? > FindAsync ( object id , CancellationToken token = default ) ;
105
+
106
+ /// <summary>
107
+ /// <para>
108
+ /// Try to find an existing entity through its unique identity (Id).
109
+ /// </para>
110
+ /// </summary>
111
+ /// <typeparam name="TId">The type o entity id.</typeparam>
112
+ /// <param name="id">The entity id.</param>
113
+ /// <param name="token">Cancellation token.</param>
114
+ /// <returns>
115
+ /// <para>
116
+ /// An entry representing the entity record obtained from the database.
117
+ /// </para>
118
+ /// </returns>
119
+ ValueTask < Entry < TEntity , TId > > FindAsync < TId > ( Id < TEntity , TId > id , CancellationToken token = default ) ;
86
120
}
87
121
88
122
/// <summary>
@@ -99,7 +133,7 @@ public interface IFinder<TEntity>
99
133
/// </remarks>
100
134
/// <typeparam name="TEntity">The entity type.</typeparam>
101
135
public interface IFinderByGuid < TEntity >
102
- where TEntity : IHasGuid
136
+ where TEntity : class , IHasGuid
103
137
{
104
138
/// <summary>
105
139
/// <para>
@@ -145,7 +179,7 @@ public interface IFinderByGuid<TEntity>
145
179
/// <typeparam name="TEntity">The entity type.</typeparam>
146
180
/// <typeparam name="TCode">The code type.</typeparam>
147
181
public interface IFinderByCode < TEntity , in TCode >
148
- where TEntity : IHasCode < TCode >
182
+ where TEntity : class , IHasCode < TCode >
149
183
{
150
184
/// <summary>
151
185
/// <para>
@@ -190,6 +224,7 @@ public interface IFinderByCode<TEntity, in TCode>
190
224
[ SuppressMessage ( "Major Code Smell" , "S2326:Unused type parameters should be removed" ,
191
225
Justification = "Update an entity, used to identify the entity" ) ]
192
226
public interface IUpdater < TEntity >
227
+ where TEntity : class
193
228
{
194
229
/// <summary>
195
230
/// <para>
@@ -272,6 +307,37 @@ IEnumerable<bool> MergeRange<TId>(IEnumerable<IHasId<TId>> models)
272
307
/// </returns>
273
308
Task < bool > MergeAsync < TId > ( IHasId < TId > model , CancellationToken token = default ) ;
274
309
310
+ /// <summary>
311
+ /// <para>
312
+ /// Operation to merge a data model to an existing entity.
313
+ /// </para>
314
+ /// </summary>
315
+ /// <remarks>
316
+ /// <para>
317
+ /// The data model should have an id, which will be used to get the entity from the database.
318
+ /// </para>
319
+ /// <para>
320
+ /// The fields of the data model should be the same as the entity's fields.
321
+ /// </para>
322
+ /// <para>
323
+ /// When implemented together with the Unit Of Work pattern the entity
324
+ /// will not be persisted directly when calling this method,
325
+ /// it will be stored in memory until the completion of the unit of work.
326
+ /// </para>
327
+ /// </remarks>
328
+ /// <typeparam name="TId">The Id type.</typeparam>
329
+ /// <typeparam name="TModel">The model with the data.</typeparam>
330
+ /// <param name="id">The id value.</param>
331
+ /// <param name="model">The model.</param>
332
+ /// <param name="token">Cancellation token.</param>
333
+ /// <returns>
334
+ /// <para>
335
+ /// True if the entity exists and has been updated, false otherwise.
336
+ /// </para>
337
+ /// </returns>
338
+ Task < bool > MergeAsync < TId , TModel > ( Id < TEntity , TId > id , TModel model , CancellationToken token = default )
339
+ where TModel : class ;
340
+
275
341
/// <summary>
276
342
/// <para>
277
343
/// Operation to merge a data model to an existing entity.
@@ -315,6 +381,7 @@ async Task<IEnumerable<bool>> MergeRangeAsync<TId>(
315
381
/// </remarks>
316
382
/// <typeparam name="TEntity">Tipo da entidade.</typeparam>
317
383
public interface IRemover < TEntity >
384
+ where TEntity : class
318
385
{
319
386
/// <summary>
320
387
/// <para>
0 commit comments