From 32ff156923eb790f430fc87c6e7c9dab0fac4c16 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 4 Mar 2015 16:35:33 -0800 Subject: [PATCH] React to DI changes, AddDataProtection no longer takes Config --- ...taProtectionServiceCollectionExtensions.cs | 38 +++++++++---------- .../DefaultDataProtectionProvider.cs | 1 - 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.AspNet.DataProtection/DataProtectionServiceCollectionExtensions.cs b/src/Microsoft.AspNet.DataProtection/DataProtectionServiceCollectionExtensions.cs index f2be8533fe..76df9b201c 100644 --- a/src/Microsoft.AspNet.DataProtection/DataProtectionServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.DataProtection/DataProtectionServiceCollectionExtensions.cs @@ -12,23 +12,21 @@ using Microsoft.AspNet.DataProtection.Dpapi; using Microsoft.AspNet.DataProtection.KeyManagement; using Microsoft.AspNet.DataProtection.Repositories; using Microsoft.AspNet.DataProtection.XmlEncryption; -using Microsoft.Framework.ConfigurationModel; namespace Microsoft.Framework.DependencyInjection { public static class DataProtectionServiceCollectionExtensions { - public static IServiceCollection AddDataProtection(this IServiceCollection services, IConfiguration configuration = null) + public static IServiceCollection AddDataProtection(this IServiceCollection services) { - services.AddOptions(configuration); - var describe = new ServiceDescriber(configuration); + services.AddOptions(); services.TryAdd(OSVersionUtil.IsBCryptOnWin7OrLaterAvailable() - ? GetDefaultServicesWindows(describe) - : GetDefaultServicesNonWindows(describe)); + ? GetDefaultServicesWindows() + : GetDefaultServicesNonWindows()); return services; } - private static IEnumerable GetDefaultServicesNonWindows(ServiceDescriber describe) + private static IEnumerable GetDefaultServicesNonWindows() { // If we're not running on Windows, we can't use CNG. @@ -36,11 +34,11 @@ namespace Microsoft.Framework.DependencyInjection // DPAPI routines don't provide authenticity. return new[] { - describe.Instance(new DpapiDataProtectionProvider(DataProtectionScope.CurrentUser)) + ServiceDescriptor.Instance(new DpapiDataProtectionProvider(DataProtectionScope.CurrentUser)) }; } - private static IEnumerable GetDefaultServicesWindows(ServiceDescriber describe) + private static IEnumerable GetDefaultServicesWindows() { List descriptors = new List(); @@ -52,8 +50,8 @@ namespace Microsoft.Framework.DependencyInjection // cloud DPAPI service comes online. descriptors.AddRange(new[] { - describe.Singleton(), - describe.Instance(new FileSystemXmlRepository(azureWebSitesKeysFolder)) + ServiceDescriptor.Singleton(), + ServiceDescriptor.Instance(new FileSystemXmlRepository(azureWebSitesKeysFolder)) }); } else @@ -64,8 +62,8 @@ namespace Microsoft.Framework.DependencyInjection { descriptors.AddRange(new[] { - describe.Instance(new DpapiXmlEncryptor(protectToLocalMachine: false)), - describe.Instance(new FileSystemXmlRepository(localAppDataKeysFolder)) + ServiceDescriptor.Instance(new DpapiXmlEncryptor(protectToLocalMachine: false)), + ServiceDescriptor.Instance(new FileSystemXmlRepository(localAppDataKeysFolder)) }); } else @@ -80,15 +78,15 @@ namespace Microsoft.Framework.DependencyInjection // We use same-machine DPAPI since we already know no user profile is loaded. descriptors.AddRange(new[] { - describe.Instance(new DpapiXmlEncryptor(protectToLocalMachine: true)), - describe.Instance(hklmRegXmlRepository) + ServiceDescriptor.Instance(new DpapiXmlEncryptor(protectToLocalMachine: true)), + ServiceDescriptor.Instance(hklmRegXmlRepository) }); } else { // Fall back to DPAPI for now return new[] { - describe.Instance(new DpapiDataProtectionProvider(DataProtectionScope.LocalMachine)) + ServiceDescriptor.Instance(new DpapiDataProtectionProvider(DataProtectionScope.LocalMachine)) }; } } @@ -97,10 +95,10 @@ namespace Microsoft.Framework.DependencyInjection // We use CNG CBC + HMAC by default. descriptors.AddRange(new[] { - describe.Singleton(), - describe.Singleton(), - describe.Singleton(), - describe.Singleton() + ServiceDescriptor.Singleton(), + ServiceDescriptor.Singleton(), + ServiceDescriptor.Singleton(), + ServiceDescriptor.Singleton() }); return descriptors; diff --git a/src/Microsoft.AspNet.DataProtection/DefaultDataProtectionProvider.cs b/src/Microsoft.AspNet.DataProtection/DefaultDataProtectionProvider.cs index 75925fe216..1aa439e917 100644 --- a/src/Microsoft.AspNet.DataProtection/DefaultDataProtectionProvider.cs +++ b/src/Microsoft.AspNet.DataProtection/DefaultDataProtectionProvider.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNet.DataProtection.KeyManagement; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.DataProtection