Skip to content

Commit 8fe9e21

Browse files
authored
Add Builder extensions (Azure#20656)
* Add Builder extensions for TableServiceClient
1 parent b8eafa8 commit 8fe9e21

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

sdk/tables/Azure.Data.Tables/api/Azure.Data.Tables.netstandard2.0.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,12 @@ public TableUriBuilder(System.Uri uri) { }
456456
public System.Uri ToUri() { throw null; }
457457
}
458458
}
459+
namespace Microsoft.Extensions.Azure
460+
{
461+
public static partial class TableClientBuilderExtensions
462+
{
463+
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Data.Tables.TableServiceClient, Azure.Data.Tables.TableClientOptions> AddTableServiceClient<TBuilder>(this TBuilder builder, string connectionString) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilder { throw null; }
464+
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Data.Tables.TableServiceClient, Azure.Data.Tables.TableClientOptions> AddTableServiceClient<TBuilder>(this TBuilder builder, System.Uri serviceUri, Azure.Data.Tables.TableSharedKeyCredential sharedKeyCredential) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilder { throw null; }
465+
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Data.Tables.TableServiceClient, Azure.Data.Tables.TableClientOptions> AddTableServiceClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilderWithConfiguration<TConfiguration> { throw null; }
466+
}
467+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using Azure.Core.Extensions;
6+
using Azure.Data.Tables;
7+
8+
namespace Microsoft.Extensions.Azure
9+
{
10+
/// <summary>
11+
/// Extension methods to add <see cref="TableClientOptions"/> client to clients builder.
12+
/// </summary>
13+
public static class TableClientBuilderExtensions
14+
{
15+
/// <summary>
16+
/// Registers a <see cref="TableServiceClient"/> instance with the provided <paramref name="connectionString"/>
17+
/// </summary>
18+
public static IAzureClientBuilder<TableServiceClient, TableClientOptions> AddTableServiceClient<TBuilder>(this TBuilder builder, string connectionString)
19+
where TBuilder : IAzureClientFactoryBuilder
20+
{
21+
return builder.RegisterClientFactory<TableServiceClient, TableClientOptions>(options => new TableServiceClient(connectionString, options));
22+
}
23+
24+
/// <summary>
25+
/// Registers a <see cref="TableServiceClient"/> instance with the provided <paramref name="serviceUri"/> and <paramref name="sharedKeyCredential"/>
26+
/// </summary>
27+
public static IAzureClientBuilder<TableServiceClient, TableClientOptions> AddTableServiceClient<TBuilder>(this TBuilder builder, Uri serviceUri, TableSharedKeyCredential sharedKeyCredential)
28+
where TBuilder : IAzureClientFactoryBuilder
29+
{
30+
return builder.RegisterClientFactory<TableServiceClient, TableClientOptions>(options => new TableServiceClient(serviceUri, sharedKeyCredential, options));
31+
}
32+
33+
/// <summary>
34+
/// Registers a <see cref="TableServiceClient"/> instance with connection options loaded from the provided <paramref name="configuration"/> instance.
35+
/// </summary>
36+
public static IAzureClientBuilder<TableServiceClient, TableClientOptions> AddTableServiceClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration)
37+
where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration>
38+
{
39+
return builder.RegisterClientFactory<TableServiceClient, TableClientOptions>(configuration);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)