MultipleAzureStorageFactoryExtensions.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. using Microsoft.Extensions.DependencyInjection;
  2. using Microsoft.Extensions.DependencyInjection.Extensions;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using TEAMModelOS.SDK.DI;
  7. namespace TEAMModelOS.SDK.DI.Multiple
  8. {
  9. public static class MultipleAzureStorageFactoryExtensions
  10. {
  11. /// <summary>
  12. /// Storage依赖注入
  13. /// </summary>
  14. /// <param name="services"></param>
  15. /// <param name="connectionInfo"></param>
  16. /// <returns></returns>
  17. /// <exception cref="ArgumentNullException"></exception>
  18. public static IServiceCollection AddMultipleAzureStorage(this IServiceCollection services, List<(string name, string connectionString)> connectionInfo)
  19. {
  20. if (services == null) throw new ArgumentNullException(nameof(services));
  21. if (connectionInfo == null) throw new ArgumentNullException(nameof(connectionInfo));
  22. services.TryAddSingleton<AzureStorageFactory>();
  23. connectionInfo.ForEach(connection =>
  24. {
  25. services.Configure<AzureStorageFactoryOptions>(connection.name, o => { o.Name = connection.name; o.StorageAccountConnectionString = connection.connectionString; });
  26. });
  27. return services;
  28. }
  29. }
  30. }