diff --git a/src/Microsoft.AspNetCore.DataProtection/DataProtectionServiceCollectionExtensions.cs b/src/Microsoft.AspNetCore.DataProtection/DataProtectionServiceCollectionExtensions.cs index e951736e1f..b112e9ac68 100644 --- a/src/Microsoft.AspNetCore.DataProtection/DataProtectionServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNetCore.DataProtection/DataProtectionServiceCollectionExtensions.cs @@ -67,7 +67,7 @@ namespace Microsoft.Extensions.DependencyInjection { if (OSVersionUtil.IsWindows()) { - services.TryAddSingleton(); + services.TryAddSingleton(); } services.TryAddEnumerable( diff --git a/src/Microsoft.AspNetCore.DataProtection/IRegistryPolicyResolver.cs b/src/Microsoft.AspNetCore.DataProtection/IRegistryPolicyResolver.cs new file mode 100644 index 0000000000..b188bf40f7 --- /dev/null +++ b/src/Microsoft.AspNetCore.DataProtection/IRegistryPolicyResolver.cs @@ -0,0 +1,13 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.DataProtection +{ + // Single implementation of this interface is conditionally added to DI on Windows + // We have to use interface because some DI implementations would try to activate class + // even if it was not registered causing problems crossplat + internal interface IRegistryPolicyResolver + { + RegistryPolicy ResolvePolicy(); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.DataProtection/Internal/KeyManagementOptionsSetup.cs b/src/Microsoft.AspNetCore.DataProtection/Internal/KeyManagementOptionsSetup.cs index a197b7ceba..10707c9cab 100644 --- a/src/Microsoft.AspNetCore.DataProtection/Internal/KeyManagementOptionsSetup.cs +++ b/src/Microsoft.AspNetCore.DataProtection/Internal/KeyManagementOptionsSetup.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.DataProtection.Internal { internal class KeyManagementOptionsSetup : IConfigureOptions { - private readonly RegistryPolicyResolver _registryPolicyResolver; + private readonly IRegistryPolicyResolver _registryPolicyResolver; private readonly ILoggerFactory _loggerFactory; public KeyManagementOptionsSetup() @@ -26,12 +26,12 @@ namespace Microsoft.AspNetCore.DataProtection.Internal { } - public KeyManagementOptionsSetup(RegistryPolicyResolver registryPolicyResolver) + public KeyManagementOptionsSetup(IRegistryPolicyResolver registryPolicyResolver) : this(NullLoggerFactory.Instance, registryPolicyResolver) { } - public KeyManagementOptionsSetup(ILoggerFactory loggerFactory, RegistryPolicyResolver registryPolicyResolver) + public KeyManagementOptionsSetup(ILoggerFactory loggerFactory, IRegistryPolicyResolver registryPolicyResolver) { _loggerFactory = loggerFactory; _registryPolicyResolver = registryPolicyResolver; diff --git a/src/Microsoft.AspNetCore.DataProtection/RegistryPolicyResolver.cs b/src/Microsoft.AspNetCore.DataProtection/RegistryPolicyResolver.cs index a6f63ee9a1..d3357fa34d 100644 --- a/src/Microsoft.AspNetCore.DataProtection/RegistryPolicyResolver.cs +++ b/src/Microsoft.AspNetCore.DataProtection/RegistryPolicyResolver.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.DataProtection /// /// A type which allows reading policy from the system registry. /// - internal sealed class RegistryPolicyResolver + internal sealed class RegistryPolicyResolver: IRegistryPolicyResolver { private readonly Func _getPolicyRegKey; private readonly IActivator _activator; @@ -88,13 +88,7 @@ namespace Microsoft.AspNetCore.DataProtection return sinks; } - /// - /// Returns a from the default registry location. - /// - public static RegistryPolicy ResolveDefaultPolicy(IActivator activator) - => new RegistryPolicyResolver(activator).ResolvePolicy(); - - internal RegistryPolicy ResolvePolicy() + public RegistryPolicy ResolvePolicy() { using (var registryKey = _getPolicyRegKey()) {