static SingletonAzureComponentFactory() { var services = new ServiceCollection(); services.AddAzureClientsCore(); Instance = services.BuildServiceProvider().GetRequiredService <AzureComponentFactory>(); }
public ServiceManagerStore(IConfiguration configuration, ILoggerFactory loggerFactory, AzureComponentFactory azureComponentFactory, IEndpointRouter router = null) { this.loggerFactory = loggerFactory; _azureComponentFactory = azureComponentFactory; this.configuration = configuration; this.router = router; }
/// <summary> /// Initializes a new instance of the <see cref="StorageClientProvider{TClient, TClientOptions}"/> class that uses the registered Azure services. /// </summary> /// <param name="componentFactory">The Azure factory responsible for creating clients. <see cref="AzureComponentFactory"/>.</param> /// <param name="logForwarder">Log forwarder that forwards events to ILogger. <see cref="AzureEventSourceLogForwarder"/>.</param> public StorageClientProvider(AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder) { _componentFactory = componentFactory; _logForwarder = logForwarder; _logForwarder.Start(); }
public QueueServiceClientProvider( IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, IOptions <QueuesOptions> queueOptions) : base(configuration, componentFactory, logForwarder) { _queuesOptions = queueOptions?.Value; }
public ServiceBusClientFactory( IConfiguration configuration, AzureComponentFactory componentFactory, MessagingProvider messagingProvider) { _configuration = configuration; _componentFactory = componentFactory; _messagingProvider = messagingProvider; }
/// <summary> /// Initializes a new instance of the <see cref="StorageClientProvider{TClient, TClientOptions}"/> class that uses the registered Azure services. /// </summary> /// <param name="configuration">The configuration to use when creating Client-specific objects. <see cref="IConfiguration"/></param> /// <param name="componentFactory">The Azure factory responsible for creating clients. <see cref="AzureComponentFactory"/></param> /// <param name="logForwarder">Log forwarder that forwards events to ILogger. <see cref="AzureEventSourceLogForwarder"/></param> /// <param name="logger">Logger used when there is an error creating a client</param> public StorageClientProvider(IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, ILogger <TClient> logger) { _configuration = configuration; _componentFactory = componentFactory; _logForwarder = logForwarder; _logger = logger; _logForwarder?.Start(); }
public OptionsSetup(IConfiguration configuration, AzureComponentFactory azureComponentFactory, string connectionStringKey) { if (string.IsNullOrWhiteSpace(connectionStringKey)) { throw new ArgumentException($"'{nameof(connectionStringKey)}' cannot be null or whitespace", nameof(connectionStringKey)); } _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); _azureComponentFactory = azureComponentFactory; _connectionStringKey = connectionStringKey; }
public ServiceBusClientFactory( IConfiguration configuration, AzureComponentFactory componentFactory, MessagingProvider messagingProvider, AzureEventSourceLogForwarder logForwarder) { _configuration = configuration; _componentFactory = componentFactory; _messagingProvider = messagingProvider; logForwarder.Start(); }
public ServiceBusClientFactory( IConfiguration configuration, AzureComponentFactory componentFactory, MessagingProvider messagingProvider, AzureEventSourceLogForwarder logForwarder, IOptions <ServiceBusOptions> options) { _configuration = configuration; _componentFactory = componentFactory; _messagingProvider = messagingProvider; _options = options?.Value ?? throw new ArgumentNullException(nameof(options)); logForwarder.Start(); }
public void UsesDefaultCredentialWhenNoneExists() { var configuration = GetConfiguration(); var serviceCollection = new ServiceCollection(); serviceCollection.AddAzureClients(builder => builder.UseCredential(new EnvironmentCredential())); ServiceProvider provider = serviceCollection.BuildServiceProvider(); AzureComponentFactory factory = provider.GetService <AzureComponentFactory>(); TokenCredential credential = factory.CreateTokenCredential(configuration); Assert.IsInstanceOf <EnvironmentCredential>(credential); }
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); }
public QueueServiceClientProvider( IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, IOptions <QueuesOptions> queueOptions, ILoggerFactory loggerFactory, IQueueProcessorFactory queueProcessorFactory, SharedQueueWatcher messageEnqueuedWatcher) : base(configuration, componentFactory, logForwarder) { _queuesOptions = queueOptions?.Value; _loggerFactory = loggerFactory; _queueProcessorFactory = queueProcessorFactory; _messageEnqueuedWatcher = messageEnqueuedWatcher; }
public void CanCreateClientWithoutRegistrationUsingConnectionString() { var configuration = GetConfiguration( new KeyValuePair <string, string>("TestClient", "http://localhost/")); var serviceCollection = new ServiceCollection(); serviceCollection.AddAzureClientsCore(); ServiceProvider provider = serviceCollection.BuildServiceProvider(); AzureComponentFactory factory = provider.GetService <AzureComponentFactory>(); TestClient client = (TestClient)factory.CreateClient(typeof(TestClient), configuration.GetSection("TestClient"), null, new TestClientOptions()); Assert.AreEqual("http://localhost/", client.ConnectionString); }
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); }
public void CanCreateClientWithoutRegistration() { var configuration = GetConfiguration( new KeyValuePair <string, string>("TestClient:uri", "http://localhost/")); var serviceCollection = new ServiceCollection(); serviceCollection.AddAzureClientsCore(); ServiceProvider provider = serviceCollection.BuildServiceProvider(); AzureComponentFactory factory = provider.GetService <AzureComponentFactory>(); TestClientWithCredentials client = (TestClientWithCredentials)factory.CreateClient(typeof(TestClientWithCredentials), configuration.GetSection("TestClient"), new EnvironmentCredential(), new TestClientOptions()); Assert.AreEqual("http://localhost/", client.Uri.ToString()); Assert.IsInstanceOf <EnvironmentCredential>(client.Credential); }
public OptionsSetup(IConfiguration configuration, ILoggerFactory loggerFactory, AzureComponentFactory azureComponentFactory, string connectionStringKey) { if (loggerFactory is null) { throw new ArgumentNullException(nameof(loggerFactory)); } if (string.IsNullOrWhiteSpace(connectionStringKey)) { throw new ArgumentException($"'{nameof(connectionStringKey)}' cannot be null or whitespace", nameof(connectionStringKey)); } this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); _azureComponentFactory = azureComponentFactory; this.connectionStringKey = connectionStringKey; logger = loggerFactory.CreateLogger <OptionsSetup>(); }
public void CanCreateCredential() { var configuration = GetConfiguration( new KeyValuePair <string, string>("TestClient:clientId", "ConfigurationClientId"), new KeyValuePair <string, string>("TestClient:clientSecret", "ConfigurationClientSecret"), new KeyValuePair <string, string>("TestClient:tenantId", "ConfigurationTenantId")); var serviceCollection = new ServiceCollection(); serviceCollection.AddAzureClientsCore(); ServiceProvider provider = serviceCollection.BuildServiceProvider(); AzureComponentFactory factory = provider.GetService <AzureComponentFactory>(); TokenCredential credential = factory.CreateTokenCredential(configuration.GetSection("TestClient")); Assert.IsInstanceOf <ClientSecretCredential>(credential); var clientSecretCredential = (ClientSecretCredential)credential; Assert.AreEqual("ConfigurationClientId", clientSecretCredential.ClientId); Assert.AreEqual("ConfigurationClientSecret", clientSecretCredential.ClientSecret); Assert.AreEqual("ConfigurationTenantId", clientSecretCredential.TenantId); }
internal static EventHubClientFactory CreateFactory(IConfiguration configuration, EventHubOptions options, AzureComponentFactory componentFactory = null) { componentFactory ??= Mock.Of <AzureComponentFactory>(); var loggerFactory = new NullLoggerFactory(); var azureEventSourceLogForwarder = new AzureEventSourceLogForwarder(loggerFactory); return(new EventHubClientFactory( configuration, componentFactory, Options.Create(options), new DefaultNameResolver(configuration), azureEventSourceLogForwarder, new CheckpointClientProvider(configuration, componentFactory, azureEventSourceLogForwarder, loggerFactory.CreateLogger <BlobServiceClient>()))); }
public static IEnumerable <ServiceEndpoint> GetEndpoints(this IConfiguration config, AzureComponentFactory azureComponentFactory) { foreach (var child in config.GetChildren()) { if (child.TryGetEndpointFromIdentity(azureComponentFactory, out var endpoint)) { yield return(endpoint); continue; } foreach (var item in child.GetNamedEndpointsFromConnectionString()) { yield return(item); } } }
public InstrumentedTableClientProvider(RecordedTestBase recording, IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, ILogger <TableServiceClient> logger) : base(configuration, componentFactory, logForwarder, logger) { _recording = recording; }
/// <summary> /// TODO. /// </summary> /// <param name="configuration"></param> /// <param name="componentFactory"></param> public StorageAccountProvider(IConfiguration configuration, AzureComponentFactory componentFactory) { _configuration = configuration; _componentFactory = componentFactory; }
public static bool TryGetNamedEndpointFromIdentity(this IConfigurationSection section, AzureComponentFactory azureComponentFactory, out ServiceEndpoint endpoint) { var text = section["ServiceUri"]; if (text != null) { var key = section.Key; var value = section.GetValue("Type", EndpointType.Primary); var credential = azureComponentFactory.CreateTokenCredential(section); endpoint = new ServiceEndpoint(new Uri(text), credential, value, key); return(true); } endpoint = null; return(false); }
public AzureClientsExtensionConfigProvider(AzureComponentFactory componentFactory, IConfiguration configuration, INameResolver nameResolver) { _componentFactory = componentFactory; _configuration = configuration; _nameResolver = nameResolver; }
public static bool TryGetEndpointFromIdentity(this IConfigurationSection section, AzureComponentFactory azureComponentFactory, out ServiceEndpoint endpoint, bool isNamed = true) { var text = section[ServiceUriKey]; if (text != null) { var key = section.Key; var name = isNamed ? key : string.Empty; var value = section.GetValue(TypeKey, EndpointType.Primary); var credential = azureComponentFactory.CreateTokenCredential(section); var serverEndpoint = section.GetValue <Uri>(ServerEndpointKey); var clientEndpoint = section.GetValue <Uri>(ClientEndpointKey); endpoint = new ServiceEndpoint(new Uri(text), credential, value, name, serverEndpoint, clientEndpoint); return(true); } endpoint = null; return(false); }
public QueueServiceClientProvider(IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder) : base(configuration, componentFactory, logForwarder) { }
public BlobServiceClientProvider(IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, ILogger <BlobServiceClient> logger) : base(configuration, componentFactory, logForwarder, logger) { }
public AzureClientValueProvider(Type clientType, AzureComponentFactory componentFactory, IConfigurationSection configuration) { _clientType = clientType; _componentFactory = componentFactory; _configuration = configuration; }
public HostAzureBlobStorageProvider(IScriptHostManager scriptHostManager, IConfiguration configuration, IOptionsMonitor <JobHostInternalStorageOptions> options, ILogger <HostAzureBlobStorageProvider> logger, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } _storageOptions = options ?? throw new ArgumentNullException(nameof(options)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _blobServiceClientProvider = new BlobServiceClientProvider(componentFactory, logForwarder); if (FeatureFlags.IsEnabled(ScriptConstants.FeatureFlagDisableMergedWebHostScriptHostConfiguration)) { Configuration = configuration; } else { if (scriptHostManager == null) { throw new ArgumentNullException(nameof(scriptHostManager)); } Configuration = new ConfigurationBuilder() .Add(new ActiveHostConfigurationSource(scriptHostManager)) .AddConfiguration(configuration) .Build(); } }
/// <summary> /// Initializes a new instance of the <see cref="BlobServiceClientProvider"/> class that uses the registered Azure services to create a BlobServiceClient. /// </summary> /// <param name="componentFactory">The Azure factory responsible for creating clients. <see cref="AzureComponentFactory"/></param> /// <param name="logForwarder">Log forwarder that forwards events to ILogger. <see cref="AzureEventSourceLogForwarder"/></param> public BlobServiceClientProvider(AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder) : base(componentFactory, logForwarder) { }