Beispiel #1
0
        public FallbackAzureClientFactory(
            IOptionsMonitor <AzureClientsGlobalOptions> globalOptions,
            IServiceProvider serviceProvider,
            AzureComponentFactory componentFactory,
            EventSourceLogForwarder logForwarder)
        {
            _configurationRoot = globalOptions.CurrentValue.ConfigurationRootResolver?.Invoke(serviceProvider);

            _componentFactory    = componentFactory;
            _logForwarder        = logForwarder;
            _clientRegistrations = new Dictionary <string, FallbackClientRegistration <TClient> >();

            foreach (var constructor in typeof(TClient).GetConstructors(BindingFlags.Public | BindingFlags.Instance))
            {
                var lastParameter = constructor.GetParameters().LastOrDefault();
                if (lastParameter != null && typeof(ClientOptions).IsAssignableFrom(lastParameter.ParameterType))
                {
                    _clientOptionType = lastParameter.ParameterType;
                    break;
                }
            }

            if (_clientOptionType == null)
            {
                throw new InvalidOperationException("Unable to detect the client option type");
            }

            _optionsFactory = (IClientOptionsFactory)ActivatorUtilities.CreateInstance(serviceProvider, typeof(ClientOptionsFactory <,>).MakeGenericType(typeof(TClient), _clientOptionType));
        }
Beispiel #2
0
        public AzureClientFactory(
            IServiceProvider serviceProvider,
            IOptionsMonitor <AzureClientsGlobalOptions> globalOptions,
            IOptionsMonitor <AzureClientCredentialOptions <TClient> > clientsOptions,
            IEnumerable <ClientRegistration <TClient> > clientRegistrations,
            IOptionsMonitor <TOptions> monitor,
            EventSourceLogForwarder logForwarder,
            AzureComponentFactory componentFactory)
        {
            _clientRegistrations = new Dictionary <string, ClientRegistration <TClient> >();
            foreach (var registration in clientRegistrations)
            {
                _clientRegistrations[registration.Name] = registration;
            }

            _serviceProvider  = serviceProvider;
            _globalOptions    = globalOptions;
            _clientsOptions   = clientsOptions;
            _monitor          = monitor;
            _logForwarder     = logForwarder;
            _componentFactory = componentFactory;
        }