/// <summary>
        /// Adds the state storage singleton.
        /// </summary>
        /// <param name="services">The services.</param>
        /// <param name="config">The configuration.</param>
        /// <returns>IServiceCollection.</returns>
        public static IServiceCollection AddStateStorageSingleton(this IServiceCollection services, ConnectionConfig config)
        {
            var instance = new Cloud.Core.Storage.AzureTableStorage.TableStorage(config)
            {
                Name = $"{config.InstanceName}-StateStorage"
            };

            services.AddSingleton <IStateStorage>(instance);
            return(services);
        }
        /// <summary>
        /// Adds the audit log singleton.
        /// </summary>
        /// <param name="services">The services.</param>
        /// <param name="config">The configuration.</param>
        /// <returns>IServiceCollection.</returns>
        public static IServiceCollection AddAuditLogSingleton(this IServiceCollection services, ServicePrincipleConfig config)
        {
            var instance = new Cloud.Core.Storage.AzureTableStorage.TableStorage(config)
            {
                Name = $"{config.InstanceName}-AuditLog"
            };

            services.AddSingleton <IAuditLogger>(instance);
            return(services);
        }
        /// <summary>
        /// Adds an instance of state storage as a singleton with a specific instance name, using managed user config to setup.  Requires the instance
        /// name, TenantId and SubscriptionId to be supplied.
        /// </summary>
        /// <param name="services">The services to extend.</param>
        /// <param name="instanceName">Name of the state storage instance to connect to.</param>
        /// <param name="tenantId">Tenant Id the instance lives in.</param>
        /// <param name="subscriptionId">Subscription Id for the tenant.</param>
        /// <returns>IServiceCollection.</returns>
        public static IServiceCollection AddStateStorageSingleton(this IServiceCollection services, string instanceName, string tenantId, string subscriptionId)
        {
            var instance = new Cloud.Core.Storage.AzureTableStorage.TableStorage(new MsiConfig
            {
                InstanceName   = instanceName,
                TenantId       = tenantId,
                SubscriptionId = subscriptionId
            })
            {
                Name = $"{instanceName}-StateStorage"
            };

            services.AddSingleton <IStateStorage>(instance);
            return(services);
        }
        /// <summary>
        /// Adds an instance of Azure table storage as a singleton with a specific instance name, using managed user config to setup.  Requires the instance
        /// name, TenantId and SubscriptionId to be supplied.
        /// </summary>
        /// <param name="services">The services to extend.</param>
        /// <param name="key">The key to use when looking up the instance from the factory.</param>
        /// <param name="instanceName">Name of the table storage instance to connect to.</param>
        /// <param name="tenantId">Tenant Id the instance lives in.</param>
        /// <param name="subscriptionId">Subscription Id for the tenant.</param>
        /// <returns>IServiceCollection.</returns>
        public static IServiceCollection AddTableStorageSingletonNamed(this IServiceCollection services, string key, string instanceName, string tenantId, string subscriptionId)
        {
            var instance = new Cloud.Core.Storage.AzureTableStorage.TableStorage(new MsiConfig
            {
                InstanceName   = instanceName,
                TenantId       = tenantId,
                SubscriptionId = subscriptionId
            });

            if (!key.IsNullOrEmpty())
            {
                instance.Name = key;
            }

            services.AddSingleton <ITableStorage>(instance);
            services.AddFactoryIfNotAdded <ITableStorage>();
            return(services);
        }