public static IServiceCollection AddAzureClients(this IServiceCollection services) { services.AddSingleton <AzureClient>(sp => { using (new DisposableStopwatch(t => Utilities.Log($"AzureUtils.FetchAzureClient() - {t} elapsed"))) { return(AzureUtils.FetchAzureClient()); } }); services.AddSingleton <KeyVaultClient>(sp => { var azureServiceTokenProvider = new AzureServiceTokenProvider(); var authCallback = new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback); return(new KeyVaultClient(authCallback)); }); services.AddSingleton <AzureKeyVaultTokenCredential>(); services.AddSingleton <IAzureKeyVaultClients, AzureKeyVaultClients>(); services.AddSingleton <IAzureKeyVaultServices, AzureKeyVaultServices>(); return(services); }