Skip to content

Commit

Permalink
add StorageSettingsExtensions
Browse files Browse the repository at this point in the history
Related to: aliencube#319
  • Loading branch information
sikutisa committed Sep 14, 2024
1 parent 0510d56 commit f77f2b5
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using AzureOpenAIProxy.ApiApp.Configurations;


namespace AzureOpenAIProxy.ApiApp.Extensions;

/// <summary>
/// This represents the extension entity for the <see cref="StorageSettings"/> class.
/// </summary>
public static class StorageSettingsExtensions
{
/// <summary>
/// Gets the Storage configuration settings by reading appsettings.json.
/// </summary>
/// <param name="services"><see cref="IServiceCollection"/> instance.</param>
/// <returns>Returns <see cref="StorageSettings"/> instance.</returns>
public static StorageSettings GetStorageSettings(this IServiceCollection services)
{
var configuration = services.BuildServiceProvider().GetService<IConfiguration>()
?? throw new InvalidOperationException($"{nameof(IConfiguration)} service is not registered.");

var settings = configuration.GetSection(StorageSettings.Name).Get<StorageSettings>()
?? throw new InvalidOperationException($"{nameof(StorageSettings)} could not be retrieved from the configuration.");

return settings;
}
}

0 comments on commit f77f2b5

Please sign in to comment.