Для дальнейшего использования - способ, которым я решил это, используя комбинацию ответов mtkachenko и Криса Пратта:
Создано BlobStorageRepositoryFactory
:
public enum BlobStorageRepositoryType
{
Core,
Quarantine
}
public interface IBlobStorageRepositoryFactory
{
void Register(BlobStorageRepositoryType type, IBlobStorageRepository blobRepository);
IBlobStorageRepository Resolve(BlobStorageRepositoryType type);
}
public class BlobStorageRepositoryFactory : IBlobStorageRepositoryFactory
{
private readonly Dictionary<BlobStorageRepositoryType, IBlobStorageRepository> _blobRepositories = new Dictionary<BlobStorageRepositoryType, IBlobStorageRepository>();
public void Register(BlobStorageRepositoryType type, IBlobStorageRepository blobRepository)
{
_blobRepositories[type] = blobRepository;
}
public IBlobStorageRepository Resolve(BlobStorageRepositoryType type)
{
return _blobRepositories[type];
}
}
Тогда в моем Startup.cs
:
var blobStorageRepositoryFactory = new BlobStorageRepositoryFactory();
blobStorageRepositoryFactory.Register(BlobStorageRepositoryType.Core, GetBlobStorageRepository(_appSettings.BlobStorageAccountName, _appSettings.BlobStorageAccountKey));
blobStorageRepositoryFactory.Register(BlobStorageRepositoryType.Quarantine, GetBlobStorageRepository(_appSettings.QuarantineBlobStorageAccountName, _appSettings.QuarantineBlobStorageAccountKey));
services.AddSingleton<IBlobStorageRepositoryFactory>(blobStorageRepositoryFactory);
private static BlobStorageRepository GetBlobStorageRepository(string accountName, string accountKey)
{
var storageCredentials = new StorageCredentials(accountName, accountKey);
var cloudBlobStorageAccount = new CloudStorageAccount(storageCredentials, true);
var cloudBlobClient = cloudBlobStorageAccount.CreateCloudBlobClient();
var blobRepository = new BlobStorageRepository(cloudBlobClient);
return blobRepository;
}
И, наконец, в моем распоряжении:
private readonly IBlobStorageRepository _blobStorageRepository;
private readonly IBlobStorageRepository _quarantineBlobStorageRepository;
public DocumentService(IBlobStorageRepositoryFactory blobStorageRepositoryFactory)
{
_blobStorageRepository = blobStorageRepositoryFactory.Resolve(BlobStorageRepositoryType.Core);
_quarantineBlobStorageRepository = blobStorageRepositoryFactory.Resolve(BlobStorageRepositoryType.Quarantine);
}