BIAzureServiceBusFactoryExtensions.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 TEAMModelBI.DI
  8. {
  9. public static class BIAzureServiceBusFactoryExtensions
  10. {
  11. /// <summary>
  12. /// Function注入
  13. /// </summary>
  14. /// <param name="services"></param>
  15. /// <param name="connectInfos"></param>
  16. /// <returns></returns>
  17. /// <exception cref="ArgumentNullException"></exception>
  18. /// <exception cref="AccessViolationException"></exception>
  19. public static IServiceCollection AddBIAzureServiceBus(this IServiceCollection services, List<(string name, string connectionString)> connectInfos)
  20. {
  21. if (services == null) throw new ArgumentNullException(nameof(services));
  22. if (connectInfos == null) throw new AccessViolationException(nameof(connectInfos));
  23. services.TryAddSingleton<AzureServiceBusFactory>();
  24. //多个注入
  25. connectInfos.ForEach(connect => {
  26. services.Configure<AzureServiceBusFactoryOptions>(connect.name, o => { o.Name = connect.name; o.ServiceBusConnectionString = connect.connectionString; });
  27. });
  28. //services.Configure<AzureServiceBusFactoryOptions>(name, o => { o.Name = name; o.ServiceBusConnectionString = connectionString; });//单一注入
  29. return services;
  30. }
  31. }
  32. }