12345678910111213141516171819202122232425262728293031323334353637 |
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.DependencyInjection.Extensions;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using TEAMModelOS.SDK.DI;
- namespace TEAMModelBI.DI
- {
- public static class BIAzureServiceBusFactoryExtensions
- {
- /// <summary>
- /// Function注入
- /// </summary>
- /// <param name="services"></param>
- /// <param name="connectInfos"></param>
- /// <returns></returns>
- /// <exception cref="ArgumentNullException"></exception>
- /// <exception cref="AccessViolationException"></exception>
- public static IServiceCollection AddBIAzureServiceBus(this IServiceCollection services, List<(string name, string connectionString)> connectInfos)
- {
- if (services == null) throw new ArgumentNullException(nameof(services));
- if (connectInfos == null) throw new AccessViolationException(nameof(connectInfos));
- services.TryAddSingleton<AzureServiceBusFactory>();
- //多个注入
- connectInfos.ForEach(connect => {
- services.Configure<AzureServiceBusFactoryOptions>(connect.name, o => { o.Name = connect.name; o.ServiceBusConnectionString = connect.connectionString; });
- });
- //services.Configure<AzureServiceBusFactoryOptions>(name, o => { o.Name = name; o.ServiceBusConnectionString = connectionString; });//单一注入
- return services;
- }
- }
- }
|