File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
src/AzureOpenAIProxy.ApiApp Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 77
88 <ItemGroup >
99 <PackageReference Include =" Azure.AI.OpenAI" Version =" $(AzureOpenAIVersion)" />
10+ <PackageReference Include =" Azure.Data.Tables" Version =" 12.9.0" />
1011 <PackageReference Include =" Azure.Identity" Version =" 1.12.0" />
1112 <PackageReference Include =" Azure.Security.KeyVault.Secrets" Version =" 4.6.0" />
1213 <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 ;
23using Azure . Security . KeyVault . Secrets ;
34
45using AzureOpenAIProxy . ApiApp . Builders ;
@@ -134,4 +135,36 @@ public static IServiceCollection AddOpenApiService(this IServiceCollection servi
134135
135136 return services ;
136137 }
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+ }
137170}
You can’t perform that action at this time.
0 commit comments