File tree 2 files changed +35
-1
lines changed
src/AzureOpenAIProxy.ApiApp
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 7
7
8
8
<ItemGroup >
9
9
<PackageReference Include =" Azure.AI.OpenAI" Version =" $(AzureOpenAIVersion)" />
10
+ <PackageReference Include =" Azure.Data.Tables" Version =" 12.9.0" />
10
11
<PackageReference Include =" Azure.Identity" Version =" 1.12.0" />
11
12
<PackageReference Include =" Azure.Security.KeyVault.Secrets" Version =" 4.6.0" />
12
13
<PackageReference Include =" Microsoft.AspNetCore.OpenApi" Version =" $(AspNetCoreVersion)" />
Original file line number Diff line number Diff line change 1
- using Azure . Identity ;
1
+ using Azure . Data . Tables ;
2
+ using Azure . Identity ;
2
3
using Azure . Security . KeyVault . Secrets ;
3
4
4
5
using AzureOpenAIProxy . ApiApp . Builders ;
@@ -134,4 +135,36 @@ public static IServiceCollection AddOpenApiService(this IServiceCollection servi
134
135
135
136
return services ;
136
137
}
138
+
139
+ /// <summary>
140
+ /// Adds the TableServiceClient to the services collection.
141
+ /// </summary>
142
+ /// <param name="services"><see cref="IServiceCollection"/> instance.</param>
143
+ /// <returns>Returns <see cref="IServiceCollection"/> instance.</returns>
144
+ public static IServiceCollection AddTableStorageService ( this IServiceCollection services )
145
+ {
146
+ services . AddSingleton < TableServiceClient > ( sp => {
147
+ var configuration = sp . GetService < IConfiguration > ( )
148
+ ?? throw new InvalidOperationException ( $ "{ nameof ( IConfiguration ) } service is not registered.") ;
149
+
150
+ var settings = configuration . GetSection ( AzureSettings . Name ) . GetSection ( StorageAccountSettings . Name ) . Get < StorageAccountSettings > ( )
151
+ ?? throw new InvalidOperationException ( $ "{ nameof ( StorageAccountSettings ) } could not be retrieved from the configuration.") ;
152
+
153
+ if ( string . IsNullOrWhiteSpace ( settings . ConnectionString ) == true )
154
+ {
155
+ throw new InvalidOperationException ( $ "{ nameof ( StorageAccountSettings . ConnectionString ) } is not defined.") ;
156
+ }
157
+
158
+ if ( string . IsNullOrWhiteSpace ( settings . ContainerName ) == true )
159
+ {
160
+ throw new InvalidOperationException ( $ "{ nameof ( StorageAccountSettings . ContainerName ) } is not defined.") ;
161
+ }
162
+
163
+ var client = new TableServiceClient ( settings . ConnectionString ) ;
164
+
165
+ return client ;
166
+ } ) ;
167
+
168
+ return services ;
169
+ }
137
170
}
You can’t perform that action at this time.
0 commit comments