diff --git a/src/Microsoft.AspNet.Security.DataProtection/DataProtectionServices.cs b/src/Microsoft.AspNet.Security.DataProtection/DataProtectionServiceCollectionExtensions.cs similarity index 90% rename from src/Microsoft.AspNet.Security.DataProtection/DataProtectionServices.cs rename to src/Microsoft.AspNet.Security.DataProtection/DataProtectionServiceCollectionExtensions.cs index 5ba4a766b1..d1e0f56124 100644 --- a/src/Microsoft.AspNet.Security.DataProtection/DataProtectionServices.cs +++ b/src/Microsoft.AspNet.Security.DataProtection/DataProtectionServiceCollectionExtensions.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Security.Cryptography; +using Microsoft.AspNet.Security.DataProtection; using Microsoft.AspNet.Security.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.Security.DataProtection.Cng; using Microsoft.AspNet.Security.DataProtection.Dpapi; @@ -12,28 +13,19 @@ using Microsoft.AspNet.Security.DataProtection.KeyManagement; using Microsoft.AspNet.Security.DataProtection.Repositories; using Microsoft.AspNet.Security.DataProtection.XmlEncryption; using Microsoft.Framework.ConfigurationModel; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.OptionsModel; -namespace Microsoft.AspNet.Security.DataProtection +namespace Microsoft.Framework.DependencyInjection { - public static class DataProtectionServices + public static class DataProtectionServiceCollectionExtensions { - public static IEnumerable GetDefaultServices() - { - return GetDefaultServices(new Configuration()); - } - - public static IEnumerable GetDefaultServices(IConfiguration configuration) + public static IServiceCollection AddDataProtection(this IServiceCollection services, IConfiguration configuration = null) { + services.AddOptions(configuration); var describe = new ServiceDescriber(configuration); - - List descriptors = new List(); - descriptors.AddRange(OptionsServices.GetDefaultServices(configuration)); - descriptors.AddRange(OSVersionUtil.IsBCryptOnWin7OrLaterAvailable() + services.TryAdd(OSVersionUtil.IsBCryptOnWin7OrLaterAvailable() ? GetDefaultServicesWindows(describe) : GetDefaultServicesNonWindows(describe)); - return descriptors; + return services; } private static IEnumerable GetDefaultServicesNonWindows(ServiceDescriber describe) diff --git a/src/Microsoft.AspNet.Security.DataProtection/DefaultDataProtectionProvider.cs b/src/Microsoft.AspNet.Security.DataProtection/DefaultDataProtectionProvider.cs index f733d8b161..9f5ed3e54d 100644 --- a/src/Microsoft.AspNet.Security.DataProtection/DefaultDataProtectionProvider.cs +++ b/src/Microsoft.AspNet.Security.DataProtection/DefaultDataProtectionProvider.cs @@ -16,10 +16,7 @@ namespace Microsoft.AspNet.Security.DataProtection public DefaultDataProtectionProvider() { // use DI defaults - var collection = new ServiceCollection(); - var defaultServices = DataProtectionServices.GetDefaultServices(); - collection.Add(defaultServices); - var serviceProvider = collection.BuildServiceProvider(); + var serviceProvider = new ServiceCollection().AddDataProtection().BuildServiceProvider(); _innerProvider = serviceProvider.GetRequiredService(); }