Skip to content

Commit

Permalink
refactor ServiceCollectionExtensions
Browse files Browse the repository at this point in the history
StorageAccountExtensions don't need to exist in their own file.

Related to: aliencube#319
  • Loading branch information
sikutisa committed Sep 16, 2024
1 parent ad91218 commit ecbe722
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,31 @@ public static IServiceCollection AddTableStorageService(this IServiceCollection
return client;
});

return services;
}

/// <summary>
/// Gets the storage account configuration settings by reading appsettings.json.
/// </summary>
/// <param name="services"><see cref="IServiceCollection"/> instance.</param>
/// <returns>Returns <see cref="StorageAccountSettings"/> instance.</returns>
public static IServiceCollection AddStorageAccountSettings(this IServiceCollection services)
{
services.AddSingleton<StorageAccountSettings>(sp => {
var configuration = sp.GetService<IConfiguration>()
?? throw new InvalidOperationException($"{nameof(IConfiguration)} service is not registered.");

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

if (string.IsNullOrWhiteSpace(settings.TableStorage.TableName) == true)
{
throw new InvalidOperationException($"{StorageAccountSettings.Name}.{TableStorageSettings.Name} is not defined.");
}

return settings;
});

return services;
}
}

This file was deleted.

0 comments on commit ecbe722

Please sign in to comment.