using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace GB5Shared.Storage
{
public static class StorageServiceExtensions
{
///
/// Registers the GB5 storage abstraction.
/// Call in Program.cs:
/// builder.Services.AddGB5Storage(builder.Configuration.GetSection("StorageConfiguration"));
/// NetworkBasePath/PathTemplate should come from HashiCorp Vault, not appsettings.json.
/// The active backend is no longer a single static provider per deployment — it's resolved
/// per tenant DB at request time via , based on that
/// tenant's own MDBLEVELSETTING.ATTACHMENTOPTION (see AttachmentStorageResolver).
///
public static IServiceCollection AddGB5Storage(
this IServiceCollection services,
IConfiguration configuration)
{
services.Configure(configuration);
// Fallback provider for the FileBased option — stateless, safe as a singleton.
// AmazonS3Client/S3StorageProvider are NOT registered here: they're built per-tenant
// by AttachmentStorageResolver from that tenant's own decrypted MDBLEVELSETTING
// credentials, since bucket/keys differ per tenant DB.
services.AddSingleton();
// Also bind IStorageProvider itself to the same singleton instance — consumers that
// don't need per-tenant resolution (IceImport's upload staging, DMS's Alfresco
// migration/ESSDocument BLLs) inject IStorageProvider directly rather than going
// through IAttachmentStorageResolver.
services.AddSingleton(sp => sp.GetRequiredService());
services.AddScoped();
return services;
}
}
}