Skip to content

Commit f77f2b5

Browse files
committed
add StorageSettingsExtensions
Related to: aliencube#319
1 parent 0510d56 commit f77f2b5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using AzureOpenAIProxy.ApiApp.Configurations;
2+
3+
4+
namespace AzureOpenAIProxy.ApiApp.Extensions;
5+
6+
/// <summary>
7+
/// This represents the extension entity for the <see cref="StorageSettings"/> class.
8+
/// </summary>
9+
public static class StorageSettingsExtensions
10+
{
11+
/// <summary>
12+
/// Gets the Storage configuration settings by reading appsettings.json.
13+
/// </summary>
14+
/// <param name="services"><see cref="IServiceCollection"/> instance.</param>
15+
/// <returns>Returns <see cref="StorageSettings"/> instance.</returns>
16+
public static StorageSettings GetStorageSettings(this IServiceCollection services)
17+
{
18+
var configuration = services.BuildServiceProvider().GetService<IConfiguration>()
19+
?? throw new InvalidOperationException($"{nameof(IConfiguration)} service is not registered.");
20+
21+
var settings = configuration.GetSection(StorageSettings.Name).Get<StorageSettings>()
22+
?? throw new InvalidOperationException($"{nameof(StorageSettings)} could not be retrieved from the configuration.");
23+
24+
return settings;
25+
}
26+
}

0 commit comments

Comments
 (0)