< Summary

Class:Microsoft.Extensions.Azure.AzureClientFactory`2
Assembly:Microsoft.Extensions.Azure
File(s):C:\Git\azure-sdk-for-net\sdk\core\Microsoft.Extensions.Azure\src\Internal\AzureClientFactory.cs
Covered lines:16
Uncovered lines:0
Coverable lines:16
Total lines:50
Line coverage:100% (16 of 16)
Covered branches:4
Total branches:4
Branch coverage:100% (4 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
CreateClient(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Microsoft.Extensions.Azure\src\Internal\AzureClientFactory.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using Microsoft.Extensions.Options;
 7
 8namespace Microsoft.Extensions.Azure
 9{
 10    internal class AzureClientFactory<TClient, TOptions>: IAzureClientFactory<TClient>
 11    {
 12        private readonly Dictionary<string, ClientRegistration<TClient, TOptions>> _clientRegistrations;
 13
 14        private readonly IServiceProvider _serviceProvider;
 15
 16        private readonly IOptionsMonitor<AzureClientCredentialOptions<TClient>> _clientsOptions;
 17
 18        private readonly IOptionsMonitor<TOptions> _monitor;
 19
 20        private readonly EventSourceLogForwarder _logForwarder;
 21
 4622        public AzureClientFactory(
 4623            IServiceProvider serviceProvider,
 4624            IOptionsMonitor<AzureClientCredentialOptions<TClient>> clientsOptions,
 4625            IEnumerable<ClientRegistration<TClient, TOptions>> clientRegistrations, IOptionsMonitor<TOptions> monitor,
 4626            EventSourceLogForwarder logForwarder)
 27        {
 4628            _clientRegistrations = new Dictionary<string, ClientRegistration<TClient, TOptions>>();
 19229            foreach (var registration in clientRegistrations)
 30            {
 5031                _clientRegistrations[registration.Name] = registration;
 32            }
 33
 4634            _serviceProvider = serviceProvider;
 4635            _clientsOptions = clientsOptions;
 4636            _monitor = monitor;
 4637            _logForwarder = logForwarder;
 4638        }
 39
 40        public TClient CreateClient(string name)
 41        {
 5242            if (!_clientRegistrations.TryGetValue(name, out ClientRegistration<TClient, TOptions> registration))
 43            {
 244                throw new InvalidOperationException($"Unable to find client registration with type '{typeof(TClient).Nam
 45            }
 46
 5047            return registration.GetClient(_monitor.Get(name), _clientsOptions.Get(name).CredentialFactory(_serviceProvid
 48        }
 49    }
 50}

Methods/Properties

.ctor(...)
CreateClient(...)