Skip to content

Commit bf9ff04

Browse files
committed
Add support for TableConnection overload for DocumentRepository
We should also be able to construct a document repository using a TableConnection.
1 parent 230788a commit bf9ff04

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/TableStorage/DocumentRepository.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,37 @@ public static IDocumentRepository<T> Create<T>(
3232
string? tableName = default,
3333
Func<T, string>? partitionKey = default,
3434
Func<T, string>? rowKey = default,
35-
IDocumentSerializer? serializer = default,
35+
IDocumentSerializer? serializer = default,
36+
bool includeProperties = false) where T : class
37+
=> Create<T>(
38+
new TableConnection(storageAccount, tableName ??= TableRepository.GetDefaultTableName<T>()),
39+
partitionKey, rowKey, serializer, includeProperties);
40+
41+
/// <summary>
42+
/// Creates an <see cref="ITableRepository{T}"/> for the given entity type
43+
/// <typeparamref name="T"/>.
44+
/// </summary>
45+
/// <typeparam name="T">The type of entity that the repository will manage.</typeparam>
46+
/// <param name="tableConnection">The storage account and table to use.</param>
47+
/// <param name="partitionKey">Optional function to retrieve the partition key for a given entity.
48+
/// If not provided, the class will need a property annotated with <see cref="PartitionKeyAttribute"/>.</param>
49+
/// <param name="rowKey">Optional function to retrieve the row key for a given entity.
50+
/// If not provided, the class will need a property annotated with <see cref="RowKeyAttribute"/>.</param>
51+
/// <param name="serializer">Optional serializer to use instead of the default <see cref="DocumentSerializer.Default"/>.</param>
52+
/// <param name="includeProperties">Whether to serialize properties as columns too, like table repositories, for easier querying.</param>
53+
/// <returns>The new <see cref="ITableRepository{T}"/>.</returns>
54+
public static IDocumentRepository<T> Create<T>(
55+
TableConnection tableConnection,
56+
Func<T, string>? partitionKey = default,
57+
Func<T, string>? rowKey = default,
58+
IDocumentSerializer? serializer = default,
3659
bool includeProperties = false) where T : class
3760
{
38-
tableName ??= TableRepository.GetDefaultTableName<T>();
3961
partitionKey ??= PartitionKeyAttribute.CreateCompiledAccessor<T>();
4062
rowKey ??= RowKeyAttribute.CreateCompiledAccessor<T>();
4163
serializer ??= DocumentSerializer.Default;
4264

43-
return new DocumentRepository<T>(storageAccount, tableName, partitionKey, rowKey, serializer, includeProperties);
65+
return new DocumentRepository<T>(tableConnection, partitionKey, rowKey, serializer, includeProperties);
4466
}
4567
}
4668
}

0 commit comments

Comments
 (0)