using FileService.Application.Ports; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using IM.InitCommon; using Microsoft.Extensions.Options; namespace FileService.Infrastructure.Storage { public class ObjectStorageRouter : IObjectStorageRouter, IDisposable { private IReadOnlyDictionary adpters; public ObjectStorageRouter(IEnumerable storages, IOptionsSnapshot options) { var adapters = storages.ToDictionary(x => x.ProviderCode, StringComparer.OrdinalIgnoreCase); foreach (var (code, provider) in options.Value.Providers.Where(x => x.Value.ProviderType is StorageProviderType.AwsS3 or StorageProviderType.Minio)) adapters[code] = new S3StorageAdapter(code, provider); this.adpters = adapters; } public void Dispose() { foreach (var adapter in adpters.Values.OfType()) adapter.Dispose(); } public IObjectStoragePort Route(string providerCode) { return this.adpters[providerCode]; } } }