File tree 3 files changed +20
-10
lines changed
src/AzureOpenAIProxy.ApiApp
3 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -13,14 +13,18 @@ public static class StorageSettingsExtensions
13
13
/// </summary>
14
14
/// <param name="services"><see cref="IServiceCollection"/> instance.</param>
15
15
/// <returns>Returns <see cref="StorageAccountSettings"/> instance.</returns>
16
- public static StorageAccountSettings GetStorageSettings ( this IServiceCollection services )
16
+ public static IServiceCollection AddStorageAccountSettings ( this IServiceCollection services )
17
17
{
18
- var configuration = services . BuildServiceProvider ( ) . GetService < IConfiguration > ( )
19
- ?? throw new InvalidOperationException ( $ "{ nameof ( IConfiguration ) } service is not registered.") ;
18
+ services . AddSingleton < StorageAccountSettings > ( sp => {
19
+ var configuration = sp . GetService < IConfiguration > ( )
20
+ ?? throw new InvalidOperationException ( $ "{ nameof ( IConfiguration ) } service is not registered.") ;
20
21
21
- var settings = configuration . GetSection ( StorageAccountSettings . Name ) . Get < StorageAccountSettings > ( )
22
- ?? throw new InvalidOperationException ( $ "{ nameof ( StorageAccountSettings ) } could not be retrieved from the configuration.") ;
22
+ var settings = configuration . GetSection ( StorageAccountSettings . Name ) . Get < StorageAccountSettings > ( )
23
+ ?? throw new InvalidOperationException ( $ "{ nameof ( StorageAccountSettings ) } could not be retrieved from the configuration.") ;
23
24
24
- return settings ;
25
+ return settings ;
26
+ } ) ;
27
+
28
+ return services ;
25
29
}
26
30
}
Original file line number Diff line number Diff line change 16
16
// Add OpenAPI service
17
17
builder . Services . AddOpenApiService ( ) ;
18
18
19
+ // Add Storage Account settings
20
+ builder . Services . AddStorageAccountSettings ( ) ;
21
+
19
22
// Add TableStorageClient
20
23
builder . Services . AddTableStorageService ( ) ;
21
24
Original file line number Diff line number Diff line change 1
- using AzureOpenAIProxy . ApiApp . Configurations ;
1
+ using Azure . Data . Tables ;
2
+
3
+ using AzureOpenAIProxy . ApiApp . Configurations ;
2
4
using AzureOpenAIProxy . ApiApp . Extensions ;
3
5
using AzureOpenAIProxy . ApiApp . Models ;
4
6
@@ -41,9 +43,10 @@ public interface IAdminEventRepository
41
43
/// <summary>
42
44
/// This represents the repository entity for the admin event.
43
45
/// </summary>
44
- public class AdminEventRepository ( IServiceCollection sc ) : IAdminEventRepository
46
+ public class AdminEventRepository ( TableServiceClient tableServiceClient , StorageAccountSettings storageAccountSettings ) : IAdminEventRepository
45
47
{
46
- private readonly StorageAccountSettings _storageSettings = sc . GetStorageSettings ( ) ;
48
+ private readonly TableServiceClient _tableServiceClient = tableServiceClient ;
49
+ private readonly StorageAccountSettings _storageAccountSettings = storageAccountSettings ;
47
50
48
51
/// <inheritdoc />
49
52
public async Task < AdminEventDetails > CreateEvent ( AdminEventDetails eventDetails )
@@ -82,7 +85,7 @@ public static class AdminEventRepositoryExtensions
82
85
/// <returns>Returns <see cref="IServiceCollection"/> instance.</returns>
83
86
public static IServiceCollection AddAdminEventRepository ( this IServiceCollection services )
84
87
{
85
- services . AddScoped < IAdminEventRepository > ( p => new AdminEventRepository ( services ) ) ;
88
+ services . AddScoped < IAdminEventRepository , AdminEventRepository > ( ) ;
86
89
87
90
return services ;
88
91
}
You can’t perform that action at this time.
0 commit comments