From 140cdfb2d2b0f5ff2bec11d70e956850d5be7488 Mon Sep 17 00:00:00 2001 From: jacalvar Date: Thu, 25 Feb 2016 11:06:47 -0800 Subject: [PATCH] Make ServiceCollectionExtensions consistent --- .../CorsServiceCollectionExtensions.cs | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.AspNetCore.Cors/CorsServiceCollectionExtensions.cs b/src/Microsoft.AspNetCore.Cors/CorsServiceCollectionExtensions.cs index 6bb7c79d85..a37681f8d4 100644 --- a/src/Microsoft.AspNetCore.Cors/CorsServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNetCore.Cors/CorsServiceCollectionExtensions.cs @@ -8,49 +8,46 @@ using Microsoft.Extensions.DependencyInjection.Extensions; namespace Microsoft.Extensions.DependencyInjection { /// - /// The extensions for enabling CORS support. + /// Extension methods for setting up cross-origin resource sharing services in an . /// public static class CorsServiceCollectionExtensions { /// - /// Add services needed to support CORS to the given . + /// Adds cross-origin resource sharing services to the specified . /// - /// The service collection to which CORS services are added. - /// The updated . - public static IServiceCollection AddCors(this IServiceCollection serviceCollection) + /// The to add services to. + public static void AddCors(this IServiceCollection services) { - if (serviceCollection == null) + if (services == null) { - throw new ArgumentNullException(nameof(serviceCollection)); + throw new ArgumentNullException(nameof(services)); } - - serviceCollection.TryAdd(ServiceDescriptor.Transient()); - serviceCollection.TryAdd(ServiceDescriptor.Transient()); - return serviceCollection; + + services.AddOptions(); + + services.TryAdd(ServiceDescriptor.Transient()); + services.TryAdd(ServiceDescriptor.Transient()); } /// - /// Add services needed to support CORS to the given . + /// Adds cross-origin resource sharing services to the specified . /// - /// The service collection to which CORS services are added. - /// A delegate which is run to configure the services. - /// The updated . - public static IServiceCollection AddCors( - this IServiceCollection serviceCollection, - Action configure) + /// The to add services to. + /// An to configure the provided . + public static void AddCors(this IServiceCollection services, Action setupAction) { - if (serviceCollection == null) + if (services == null) { - throw new ArgumentNullException(nameof(serviceCollection)); + throw new ArgumentNullException(nameof(services)); } - if (configure == null) + if (setupAction == null) { - throw new ArgumentNullException(nameof(configure)); + throw new ArgumentNullException(nameof(setupAction)); } - serviceCollection.Configure(configure); - return serviceCollection.AddCors(); + services.AddCors(); + services.Configure(setupAction); } } } \ No newline at end of file