private BlobClientOptions CreateBlobClientOptions(IConfiguration configuration)
        {
            var blobClientOptions = (BlobClientOptions)_componentFactory.CreateClientOptions(typeof(BlobClientOptions), null, configuration);

            if (SkuUtility.IsDynamicSku)
            {
                blobClientOptions.Transport = CreateTransportForDynamicSku();
            }

            return(blobClientOptions);
        }
        private TClientOptions CreateClientOptions(IConfiguration configuration)
        {
            var clientOptions = (TClientOptions)_componentFactory.CreateClientOptions(typeof(TClientOptions), null, configuration);

            clientOptions.Diagnostics.ApplicationId ??= "AzureWebJobs";
            if (SkuUtility.IsDynamicSku)
            {
                clientOptions.Transport = CreateTransportForDynamicSku();
            }

            return(clientOptions);
        }
Example #3
0
        public void GlobalOptionsAppliedToAzureComponentFactoryCreateClientOptions()
        {
            var configuration = GetConfiguration();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder.ConfigureDefaults(clientOptions => clientOptions.Diagnostics.ApplicationId = "AppId"));

            ServiceProvider       provider = serviceCollection.BuildServiceProvider();
            AzureComponentFactory factory  = provider.GetService <AzureComponentFactory>();
            TestClientOptions     options  = (TestClientOptions)factory.CreateClientOptions(typeof(TestClientOptions), configuration["TestClient"], null);

            Assert.AreEqual("AppId", options.Diagnostics.ApplicationId);
        }
Example #4
0
        public void CanReadClientOptionsFromConfiguration()
        {
            var configuration = GetConfiguration(
                new KeyValuePair <string, string>("TestClient:Property", "client option value"));

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClientsCore();

            ServiceProvider       provider = serviceCollection.BuildServiceProvider();
            AzureComponentFactory factory  = provider.GetService <AzureComponentFactory>();
            TestClientOptions     options  = (TestClientOptions)factory.CreateClientOptions(typeof(TestClientOptions), null, configuration.GetSection("TestClient"));

            Assert.AreEqual("client option value", options.Property);
        }
Example #5
0
            public Task <object> GetValueAsync()
            {
                Type clientOptionType = null;

                foreach (var constructor in _clientType.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");
                }

                var credential = _componentFactory.CreateTokenCredential(_configuration);
                var options    = _componentFactory.CreateClientOptions(clientOptionType, null, _configuration);

                return(Task.FromResult(_componentFactory.CreateClient(_clientType, _configuration, credential, options)));
            }
        private TClientOptions CreateClientOptions(IConfiguration configuration)
        {
            var clientOptions = (TClientOptions)_componentFactory.CreateClientOptions(typeof(TClientOptions), null, configuration);

            return(clientOptions);
        }