Make RegistryPolicyResolver an interface to fix 3d party DI (#275)

This commit is contained in:
Pavel Krymets 2017-09-18 13:43:45 -07:00 committed by GitHub
parent ee009982dc
commit 46dadbb186
4 changed files with 19 additions and 12 deletions

View File

@ -67,7 +67,7 @@ namespace Microsoft.Extensions.DependencyInjection
{
if (OSVersionUtil.IsWindows())
{
services.TryAddSingleton<RegistryPolicyResolver>();
services.TryAddSingleton<IRegistryPolicyResolver, RegistryPolicyResolver>();
}
services.TryAddEnumerable(

View File

@ -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();
}
}

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.DataProtection.Internal
{
internal class KeyManagementOptionsSetup : IConfigureOptions<KeyManagementOptions>
{
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;

View File

@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.DataProtection
/// <summary>
/// A type which allows reading policy from the system registry.
/// </summary>
internal sealed class RegistryPolicyResolver
internal sealed class RegistryPolicyResolver: IRegistryPolicyResolver
{
private readonly Func<RegistryKey> _getPolicyRegKey;
private readonly IActivator _activator;
@ -88,13 +88,7 @@ namespace Microsoft.AspNetCore.DataProtection
return sinks;
}
/// <summary>
/// Returns a <see cref="RegistryPolicy"/> from the default registry location.
/// </summary>
public static RegistryPolicy ResolveDefaultPolicy(IActivator activator)
=> new RegistryPolicyResolver(activator).ResolvePolicy();
internal RegistryPolicy ResolvePolicy()
public RegistryPolicy ResolvePolicy()
{
using (var registryKey = _getPolicyRegKey())
{