diff --git a/src/Microsoft.AspNetCore.DataProtection/DataProtectionServiceDescriptors.cs b/src/Microsoft.AspNetCore.DataProtection/DataProtectionServiceDescriptors.cs index 6727730c92..388454fc01 100644 --- a/src/Microsoft.AspNetCore.DataProtection/DataProtectionServiceDescriptors.cs +++ b/src/Microsoft.AspNetCore.DataProtection/DataProtectionServiceDescriptors.cs @@ -24,20 +24,6 @@ namespace Microsoft.Extensions.DependencyInjection /// internal static class DataProtectionServiceDescriptors { - /// - /// An backed by the host-provided defaults. - /// - public static ServiceDescriptor ConfigureOptions_DataProtectionOptions() - { - return ServiceDescriptor.Transient>(services => - { - return new ConfigureOptions(options => - { - options.ApplicationDiscriminator = services.GetApplicationUniqueIdentifier(); - }); - }); - } - /// /// An where the key lifetime is specified explicitly. /// @@ -53,14 +39,6 @@ namespace Microsoft.Extensions.DependencyInjection }); } - /// - /// An backed by default algorithmic options. - /// - public static ServiceDescriptor IAuthenticatedEncryptorConfiguration_Default() - { - return IAuthenticatedEncryptorConfiguration_FromSettings(new AuthenticatedEncryptionSettings()); - } - /// /// An backed by an . /// @@ -79,18 +57,6 @@ namespace Microsoft.Extensions.DependencyInjection } #endif - /// - /// An backed by the default keyring. - /// - public static ServiceDescriptor IDataProtectionProvider_Default() - { - return ServiceDescriptor.Singleton( - services => DataProtectionProviderFactory.GetProviderFromServices( - options: services.GetRequiredService>().Value, - services: services, - mustCreateImmediately: true /* this is the ultimate fallback */)); - } - /// /// An ephemeral . /// @@ -110,14 +76,6 @@ namespace Microsoft.Extensions.DependencyInjection return ServiceDescriptor.Singleton(services => services.GetActivator().CreateInstance(implementationTypeName)); } - /// - /// An backed by the default XML key manager. - /// - public static ServiceDescriptor IKeyManager_Default() - { - return ServiceDescriptor.Singleton(services => new XmlKeyManager(services)); - } - #if !NETSTANDARD1_3 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml /// @@ -167,14 +125,6 @@ namespace Microsoft.Extensions.DependencyInjection return ServiceDescriptor.Singleton(services => new FileSystemXmlRepository(directory, services)); } - /// - /// An backed by volatile in-process memory. - /// - public static ServiceDescriptor IXmlRepository_InMemory() - { - return ServiceDescriptor.Singleton(services => new EphemeralXmlRepository(services)); - } - /// /// An backed by the Windows registry. /// diff --git a/src/Microsoft.AspNetCore.DataProtection/DataProtectionServices.cs b/src/Microsoft.AspNetCore.DataProtection/DataProtectionServices.cs index 14c9bb9df2..1eca20601e 100644 --- a/src/Microsoft.AspNetCore.DataProtection/DataProtectionServices.cs +++ b/src/Microsoft.AspNetCore.DataProtection/DataProtectionServices.cs @@ -5,12 +5,14 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Cryptography.Cng; using Microsoft.AspNetCore.DataProtection; +using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption; using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel; using Microsoft.AspNetCore.DataProtection.Cng; using Microsoft.AspNetCore.DataProtection.KeyManagement; using Microsoft.AspNetCore.DataProtection.KeyManagement.Internal; using Microsoft.AspNetCore.DataProtection.Repositories; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Microsoft.Win32; namespace Microsoft.Extensions.DependencyInjection @@ -92,7 +94,8 @@ namespace Microsoft.Extensions.DependencyInjection { // Final fallback - use an ephemeral repository since we don't know where else to go. // This can only be used for development scenarios. - keyRepositoryDescriptor = DataProtectionServiceDescriptors.IXmlRepository_InMemory(); + keyRepositoryDescriptor = ServiceDescriptor.Singleton( + s => new EphemeralXmlRepository(s)); log?.UsingEphemeralKeyRepository(); } @@ -106,8 +109,13 @@ namespace Microsoft.Extensions.DependencyInjection }); // Provide root key management and data protection services - yield return DataProtectionServiceDescriptors.IKeyManager_Default(); - yield return DataProtectionServiceDescriptors.IDataProtectionProvider_Default(); + yield return ServiceDescriptor.Singleton(services => new XmlKeyManager(services)); + + yield return ServiceDescriptor.Singleton( + services => DataProtectionProviderFactory.GetProviderFromServices( + options: services.GetRequiredService>().Value, + services: services, + mustCreateImmediately: true /* this is the ultimate fallback */)); // Provide services required for XML encryption #if !NETSTANDARD1_3 // [[ISSUE60]] Remove this #ifdef when Core CLR gets support for EncryptedXml @@ -115,7 +123,13 @@ namespace Microsoft.Extensions.DependencyInjection #endif // Hook up the logic which allows populating default options - yield return DataProtectionServiceDescriptors.ConfigureOptions_DataProtectionOptions(); + yield return ServiceDescriptor.Transient>(services => + { + return new ConfigureOptions(options => + { + options.ApplicationDiscriminator = services.GetApplicationUniqueIdentifier(); + }); + }); // Read and apply policy from the registry, overriding any other defaults. bool encryptorConfigurationReadFromRegistry = false; @@ -134,7 +148,8 @@ namespace Microsoft.Extensions.DependencyInjection // Finally, provide a fallback encryptor configuration if one wasn't already specified. if (!encryptorConfigurationReadFromRegistry) { - yield return DataProtectionServiceDescriptors.IAuthenticatedEncryptorConfiguration_Default(); + yield return DataProtectionServiceDescriptors.IAuthenticatedEncryptorConfiguration_FromSettings( + new AuthenticatedEncryptionSettings());; } } }