Make ServiceCollectionExtensions consistent

This commit is contained in:
jacalvar 2016-02-25 11:06:47 -08:00
parent f29649c749
commit 140cdfb2d2
1 changed files with 21 additions and 24 deletions

View File

@ -8,49 +8,46 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Microsoft.Extensions.DependencyInjection namespace Microsoft.Extensions.DependencyInjection
{ {
/// <summary> /// <summary>
/// The <see cref="IServiceCollection"/> extensions for enabling CORS support. /// Extension methods for setting up cross-origin resource sharing services in an <see cref="IServiceCollection" />.
/// </summary> /// </summary>
public static class CorsServiceCollectionExtensions public static class CorsServiceCollectionExtensions
{ {
/// <summary> /// <summary>
/// Add services needed to support CORS to the given <paramref name="serviceCollection"/>. /// Adds cross-origin resource sharing services to the specified <see cref="IServiceCollection" />.
/// </summary> /// </summary>
/// <param name="serviceCollection">The service collection to which CORS services are added.</param> /// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
/// <returns>The updated <see cref="IServiceCollection"/>.</returns> public static void AddCors(this IServiceCollection services)
public static IServiceCollection AddCors(this IServiceCollection serviceCollection)
{ {
if (serviceCollection == null) if (services == null)
{ {
throw new ArgumentNullException(nameof(serviceCollection)); throw new ArgumentNullException(nameof(services));
} }
serviceCollection.TryAdd(ServiceDescriptor.Transient<ICorsService, CorsService>()); services.AddOptions();
serviceCollection.TryAdd(ServiceDescriptor.Transient<ICorsPolicyProvider, DefaultCorsPolicyProvider>());
return serviceCollection; services.TryAdd(ServiceDescriptor.Transient<ICorsService, CorsService>());
services.TryAdd(ServiceDescriptor.Transient<ICorsPolicyProvider, DefaultCorsPolicyProvider>());
} }
/// <summary> /// <summary>
/// Add services needed to support CORS to the given <paramref name="serviceCollection"/>. /// Adds cross-origin resource sharing services to the specified <see cref="IServiceCollection" />.
/// </summary> /// </summary>
/// <param name="serviceCollection">The service collection to which CORS services are added.</param> /// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
/// <param name="configure">A delegate which is run to configure the services.</param> /// <param name="setupAction">An <see cref="Action{CorsOptions}"/> to configure the provided <see cref="CorsOptions"/>.</param>
/// <returns>The updated <see cref="IServiceCollection"/>.</returns> public static void AddCors(this IServiceCollection services, Action<CorsOptions> setupAction)
public static IServiceCollection AddCors(
this IServiceCollection serviceCollection,
Action<CorsOptions> configure)
{ {
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); services.AddCors();
return serviceCollection.AddCors(); services.Configure(setupAction);
} }
} }
} }