29 lines
1.1 KiB
C#
29 lines
1.1 KiB
C#
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<string, IObjectStoragePort> adpters;
|
|
|
|
public ObjectStorageRouter(IEnumerable<IObjectStoragePort> storages, IOptionsSnapshot<StorageOptions> 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<S3StorageAdapter>()) adapter.Dispose(); } public IObjectStoragePort Route(string providerCode)
|
|
{
|
|
return this.adpters[providerCode];
|
|
}
|
|
}
|
|
}
|