77
88namespace Winton . DomainModelling . DocumentDb
99{
10+ /// <inheritdoc />
11+ /// <summary>
12+ /// An abstraction layer over <see cref="Entity{TEntityId}" /> CRUD operations in DocumentDb. Allows multiple entity
13+ /// types to be transparently stored in one collection using a 'wrapper' document type with a type discriminator and
14+ /// namespaced ID.
15+ /// </summary>
1016 public sealed class EntityFacade : IEntityFacade
1117 {
1218 private readonly Database _database ;
1319 private readonly IDocumentClient _documentClient ;
1420 private readonly DocumentCollection _documentCollection ;
1521
22+ /// <summary>
23+ /// Initializes a new instance of the <see cref="EntityFacade" /> class.
24+ /// </summary>
25+ /// <param name="database">The DocumentDb database.</param>
26+ /// <param name="documentCollection">The DocumentDb collection. Partitioned collections are not supported.</param>
27+ /// <param name="documentClient">A document client implementation.</param>
1628 public EntityFacade ( Database database , DocumentCollection documentCollection , IDocumentClient documentClient )
1729 {
1830 if ( documentCollection . PartitionKey . Paths . Any ( ) )
@@ -25,6 +37,16 @@ public EntityFacade(Database database, DocumentCollection documentCollection, ID
2537 _documentClient = documentClient ;
2638 }
2739
40+ /// <inheritdoc />
41+ /// <summary>
42+ /// Create an <see cref="T:Winton.DomainModelling.Entity`1" /> of a specified type. Supports automatic ID generation
43+ /// for
44+ /// <see cref="T:System.String" />-serializable ID types, otherwise IDs must be set before creating.
45+ /// </summary>
46+ /// <typeparam name="TEntity">The type of the entity.</typeparam>
47+ /// <typeparam name="TEntityId">The ID type of the entity.</typeparam>
48+ /// <param name="entity">The <see cref="T:Winton.DomainModelling.Entity`1" /> to persist.</param>
49+ /// <returns>The created <see cref="T:Winton.DomainModelling.Entity`1" />.</returns>
2850 public async Task < TEntity > Create < TEntity , TEntityId > ( TEntity entity )
2951 where TEntity : Entity < TEntityId >
3052 where TEntityId : IEquatable < TEntityId >
@@ -38,13 +60,28 @@ public async Task<TEntity> Create<TEntity, TEntityId>(TEntity entity)
3860 return responseDocument . Entity ;
3961 }
4062
63+ /// <inheritdoc />
64+ /// <summary>
65+ /// Delete an <see cref="T:Winton.DomainModelling.Entity`1" /> of a specified type by ID.
66+ /// </summary>
67+ /// <typeparam name="TEntity">The type of the entity.</typeparam>
68+ /// <typeparam name="TEntityId">The ID type of the entity.</typeparam>
69+ /// <param name="id">The ID of the <see cref="T:Winton.DomainModelling.Entity`1" /> to delete.</param>
70+ /// <returns>A Task.</returns>
4171 public async Task Delete < TEntity , TEntityId > ( TEntityId id )
4272 where TEntity : Entity < TEntityId >
4373 where TEntityId : IEquatable < TEntityId >
4474 {
4575 await _documentClient . DeleteDocumentAsync ( GetUri < TEntity , TEntityId > ( id ) ) ;
4676 }
4777
78+ /// <inheritdoc />
79+ /// <summary>
80+ /// Query <see cref="T:Winton.DomainModelling.Entity`1" /> instances of a specified type.
81+ /// </summary>
82+ /// <typeparam name="TEntity">The type of the entity.</typeparam>
83+ /// <typeparam name="TEntityId">The ID type of the entity.</typeparam>
84+ /// <returns>An <see cref="T:System.Linq.IQueryable`1" />.</returns>
4885 public IQueryable < TEntity > Query < TEntity , TEntityId > ( )
4986 where TEntity : Entity < TEntityId >
5087 where TEntityId : IEquatable < TEntityId >
@@ -56,6 +93,14 @@ public IQueryable<TEntity> Query<TEntity, TEntityId>()
5693 . Select ( x => x . Entity ) ;
5794 }
5895
96+ /// <inheritdoc />
97+ /// <summary>
98+ /// Read an <see cref="T:Winton.DomainModelling.Entity`1" /> of a specified type by ID.
99+ /// </summary>
100+ /// <typeparam name="TEntity">The type of the entity.</typeparam>
101+ /// <typeparam name="TEntityId">The ID type of the entity.</typeparam>
102+ /// <param name="id">The ID of the <see cref="T:Winton.DomainModelling.Entity`1" /> to read.</param>
103+ /// <returns>The <see cref="T:Winton.DomainModelling.Entity`1" /> with the given ID, if it exists, otherwise null.</returns>
59104 public async Task < TEntity > Read < TEntity , TEntityId > ( TEntityId id )
60105 where TEntity : Entity < TEntityId >
61106 where TEntityId : IEquatable < TEntityId >
@@ -75,6 +120,14 @@ public async Task<TEntity> Read<TEntity, TEntityId>(TEntityId id)
75120 }
76121 }
77122
123+ /// <inheritdoc />
124+ /// <summary>
125+ /// Upsert an <see cref="T:Winton.DomainModelling.Entity`1" /> of a specified type. The ID must be set.
126+ /// </summary>
127+ /// <typeparam name="TEntity">The type of the entity.</typeparam>
128+ /// <typeparam name="TEntityId">The ID type of the entity.</typeparam>
129+ /// <param name="entity">The <see cref="T:Winton.DomainModelling.Entity`1" /> to upsert.</param>
130+ /// <returns>The upserted <see cref="T:Winton.DomainModelling.Entity`1" />.</returns>
78131 public async Task < TEntity > Upsert < TEntity , TEntityId > ( TEntity entity )
79132 where TEntity : Entity < TEntityId >
80133 where TEntityId : IEquatable < TEntityId >
0 commit comments