44using Azure . Core ;
55using Azure . Data . AppConfiguration ;
66using Microsoft . Extensions . Azure ;
7+ using Microsoft . Extensions . Configuration . AzureAppConfiguration . Afd ;
78using Microsoft . Extensions . Configuration . AzureAppConfiguration . AzureKeyVault ;
89using Microsoft . Extensions . Configuration . AzureAppConfiguration . Extensions ;
910using Microsoft . Extensions . Configuration . AzureAppConfiguration . FeatureManagement ;
@@ -132,7 +133,7 @@ internal IEnumerable<IKeyValueAdapter> Adapters
132133 /// <summary>
133134 /// Options used to configure the client used to communicate with Azure App Configuration.
134135 /// </summary>
135- internal ConfigurationClientOptions ClientOptions { get ; } = GetDefaultClientOptions ( ) ;
136+ internal ConfigurationClientOptions ClientOptions { get ; private set ; } = GetDefaultClientOptions ( ) ;
136137
137138 /// <summary>
138139 /// Flag to indicate whether Key Vault options have been configured.
@@ -154,6 +155,11 @@ internal IEnumerable<IKeyValueAdapter> Adapters
154155 /// </summary>
155156 internal StartupOptions Startup { get ; set ; } = new StartupOptions ( ) ;
156157
158+ /// <summary>
159+ /// Gets a value indicating whether Azure Front Door is used.
160+ /// </summary>
161+ internal bool IsAfdUsed { get ; private set ; }
162+
157163 /// <summary>
158164 /// Client factory that is responsible for creating instances of ConfigurationClient.
159165 /// </summary>
@@ -186,11 +192,12 @@ public AzureAppConfigurationOptions()
186192 public AzureAppConfigurationOptions SetClientFactory ( IAzureClientFactory < ConfigurationClient > factory )
187193 {
188194 ClientFactory = factory ?? throw new ArgumentNullException ( nameof ( factory ) ) ;
195+
189196 return this ;
190197 }
191198
192199 /// <summary>
193- /// Specify what key-values to include in the configuration provider.
200+ /// Specifies what key-values to include in the configuration provider.
194201 /// <see cref="Select"/> can be called multiple times to include multiple sets of key-values.
195202 /// </summary>
196203 /// <param name="keyFilter">
@@ -262,7 +269,7 @@ public AzureAppConfigurationOptions Select(string keyFilter, string labelFilter
262269 }
263270
264271 /// <summary>
265- /// Specify a snapshot and include its contained key-values in the configuration provider.
272+ /// Specifies a snapshot and include its contained key-values in the configuration provider.
266273 /// <see cref="SelectSnapshot"/> can be called multiple times to include key-values from multiple snapshots.
267274 /// </summary>
268275 /// <param name="name">The name of the snapshot in Azure App Configuration.</param>
@@ -351,7 +358,7 @@ public AzureAppConfigurationOptions Connect(string connectionString)
351358 throw new ArgumentNullException ( nameof ( connectionString ) ) ;
352359 }
353360
354- return Connect ( new List < string > { connectionString } ) ;
361+ return Connect ( new string [ ] { connectionString } ) ;
355362 }
356363
357364 /// <summary>
@@ -362,6 +369,11 @@ public AzureAppConfigurationOptions Connect(string connectionString)
362369 /// </param>
363370 public AzureAppConfigurationOptions Connect ( IEnumerable < string > connectionStrings )
364371 {
372+ if ( IsAfdUsed )
373+ {
374+ throw new InvalidOperationException ( ErrorMessages . ConnectionConflict ) ;
375+ }
376+
365377 if ( connectionStrings == null || ! connectionStrings . Any ( ) )
366378 {
367379 throw new ArgumentNullException ( nameof ( connectionStrings ) ) ;
@@ -395,7 +407,7 @@ public AzureAppConfigurationOptions Connect(Uri endpoint, TokenCredential creden
395407 throw new ArgumentNullException ( nameof ( credential ) ) ;
396408 }
397409
398- return Connect ( new List < Uri > ( ) { endpoint } , credential ) ;
410+ return Connect ( new Uri [ ] { endpoint } , credential ) ;
399411 }
400412
401413 /// <summary>
@@ -405,6 +417,11 @@ public AzureAppConfigurationOptions Connect(Uri endpoint, TokenCredential creden
405417 /// <param name="credential">Token credential to use to connect.</param>
406418 public AzureAppConfigurationOptions Connect ( IEnumerable < Uri > endpoints , TokenCredential credential )
407419 {
420+ if ( IsAfdUsed )
421+ {
422+ throw new InvalidOperationException ( ErrorMessages . ConnectionConflict ) ;
423+ }
424+
408425 if ( endpoints == null || ! endpoints . Any ( ) )
409426 {
410427 throw new ArgumentNullException ( nameof ( endpoints ) ) ;
@@ -416,12 +433,40 @@ public AzureAppConfigurationOptions Connect(IEnumerable<Uri> endpoints, TokenCre
416433 }
417434
418435 Credential = credential ?? throw new ArgumentNullException ( nameof ( credential ) ) ;
419-
420436 Endpoints = endpoints ;
421437 ConnectionStrings = null ;
422438 return this ;
423439 }
424440
441+ /// <summary>
442+ /// Connect the provider to Azure Front Door endpoint.
443+ /// </summary>
444+ /// <param name="endpoint">The endpoint of the Azure Front Door instance to connect to.</param>
445+ public AzureAppConfigurationOptions ConnectAzureFrontDoor ( Uri endpoint )
446+ {
447+ if ( ( Credential != null && ! ( Credential is EmptyTokenCredential ) ) || ( ConnectionStrings ? . Any ( ) ?? false ) )
448+ {
449+ throw new InvalidOperationException ( ErrorMessages . ConnectionConflict ) ;
450+ }
451+
452+ if ( IsAfdUsed )
453+ {
454+ throw new InvalidOperationException ( ErrorMessages . AfdConnectionConflict ) ;
455+ }
456+
457+ if ( endpoint == null )
458+ {
459+ throw new ArgumentNullException ( nameof ( endpoint ) ) ;
460+ }
461+
462+ Credential ??= new EmptyTokenCredential ( ) ;
463+
464+ Endpoints = new Uri [ ] { endpoint } ;
465+ ConnectionStrings = null ;
466+ IsAfdUsed = true ;
467+ return this ;
468+ }
469+
425470 /// <summary>
426471 /// Trims the provided prefix from the keys of all key-values retrieved from Azure App Configuration.
427472 /// </summary>
0 commit comments