Table of Contents

Class ServiceCollectionExtensions

Namespace
Kentico.Xperience.AzureStorage
Assembly
Kentico.Xperience.AzureStorage.dll

Extension methods for configuring Azure services in the dependency injection container.

public static class ServiceCollectionExtensions
Inheritance
object
ServiceCollectionExtensions

Methods

AddAppServiceStoragePathMapping(IServiceCollection, Action<AzureStoragePathMappingOptions>)

Enables automatic mapping of registered storage paths to Azure Blob storage providers in Azure App Service hosting environments.

public static IServiceCollection AddAppServiceStoragePathMapping(this IServiceCollection services, Action<AzureStoragePathMappingOptions> configureOptions = null)

Parameters

services IServiceCollection

The Microsoft.Extensions.DependencyInjection.IServiceCollection to add the services to.

configureOptions Action<AzureStoragePathMappingOptions>

Optional callback for configuring AzureStoragePathMappingOptions.

Returns

IServiceCollection

The same Microsoft.Extensions.DependencyInjection.IServiceCollection so that additional calls can be chained.

Remarks

This method enables the Azure storage module to automatically map all registered storage paths to Azure Blob storage after application initialization.

SharedPersistent paths are mapped to Azure Blob storage. SharedTemp paths are mapped to file system storage.

Use IsMappingEnabled to control whether mapping is active based on the hosting environment. Typically disabled in local development:

builder.Services.AddAppServiceStoragePathMapping(options =>
    options.IsMappingEnabled = !builder.Environment.IsDevelopment());

Use CreateProviderForPath to override the storage provider for specific paths. The callback receives the PathRegistration and returns a custom StorageProvider. This can be used to route individual paths to a completely different storage technology, such as Amazon S3 or a shared network path, independently of the default Azure Blob mapping.

This method cannot be combined with AddXperienceCloudStoragePathMapping. Configuring both will throw an System.InvalidOperationException during application startup.

Exceptions

ArgumentNullException

Thrown when services is null.

InvalidOperationException

Thrown when storage path mapping is already configured (e.g., AddXperienceCloudStoragePathMapping was also called).

AddAzureStorageCredential(IServiceCollection, Func<IServiceProvider, TokenCredential>)

Configures Azure Storage to use TokenCredential-based authentication (managed identity) instead of shared key authentication.

public static IServiceCollection AddAzureStorageCredential(this IServiceCollection services, Func<IServiceProvider, TokenCredential> credentialFactory)

Parameters

services IServiceCollection

The service collection to add the credential factory to.

credentialFactory Func<IServiceProvider, TokenCredential>

A factory function that receives the service provider and returns a Azure.Core.TokenCredential. The service provider can be used to resolve other services needed for credential configuration.

Returns

IServiceCollection

The service collection for chaining.

Remarks

See official Microsoft documentation on how to configure the managed identity credentials.