diff --git a/samples/UseOptions/Startup.cs b/samples/UseOptions/Startup.cs
index 5c29d7f67d..732cfbca1e 100644
--- a/samples/UseOptions/Startup.cs
+++ b/samples/UseOptions/Startup.cs
@@ -9,9 +9,7 @@ namespace UseOptions
{
public void ConfigureServices(IServiceCollection services)
{
- services.AddCors();
- services.ConfigureCors(
- options =>
+ services.AddCors(options =>
options.AddPolicy("allowSingleOrigin", builder => builder.WithOrigins("http://example.com")));
}
diff --git a/src/Microsoft.AspNet.Cors.Core/CorsServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Cors.Core/CorsServiceCollectionExtensions.cs
index e46363ad97..e4e3eccf6b 100644
--- a/src/Microsoft.AspNet.Cors.Core/CorsServiceCollectionExtensions.cs
+++ b/src/Microsoft.AspNet.Cors.Core/CorsServiceCollectionExtensions.cs
@@ -2,8 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
+using Microsoft.AspNet.Cors;
using Microsoft.AspNet.Cors.Core;
+using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection.Extensions;
+using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection
{
@@ -13,12 +16,30 @@ namespace Microsoft.Framework.DependencyInjection
public static class CorsServiceCollectionExtensions
{
///
- /// Can be used to configure services in the .
+ /// Add services needed to support CORS to the given .
///
- /// The service collection which needs to be configured.
+ /// The service collection to which CORS services are added.
+ /// The updated .
+ public static IServiceCollection AddCors(this IServiceCollection serviceCollection)
+ {
+ if (serviceCollection == null)
+ {
+ throw new ArgumentNullException(nameof(serviceCollection));
+ }
+
+ serviceCollection.AddOptions();
+ serviceCollection.TryAdd(ServiceDescriptor.Transient());
+ serviceCollection.TryAdd(ServiceDescriptor.Transient());
+ return serviceCollection;
+ }
+
+ ///
+ /// Add services needed to support CORS to the given .
+ ///
+ /// The service collection to which CORS services are added.
/// A delegate which is run to configure the services.
- ///
- public static IServiceCollection ConfigureCors(
+ /// The updated .
+ public static IServiceCollection AddCors(
this IServiceCollection serviceCollection,
Action configure)
{
@@ -32,20 +53,8 @@ namespace Microsoft.Framework.DependencyInjection
throw new ArgumentNullException(nameof(configure));
}
- return serviceCollection.Configure(configure);
- }
-
- ///
- /// Add services needed to support CORS to the given .
- ///
- /// The service collection to which CORS services are added.
- /// The updated .
- public static IServiceCollection AddCors(this IServiceCollection serviceCollection)
- {
- serviceCollection.AddOptions();
- serviceCollection.TryAdd(ServiceDescriptor.Transient());
- serviceCollection.TryAdd(ServiceDescriptor.Transient());
- return serviceCollection;
+ serviceCollection.Configure(configure);
+ return serviceCollection.AddCors();
}
}
}
\ No newline at end of file
diff --git a/test/Microsoft.AspNet.Cors.Test/CorsMiddlewareTests.cs b/test/Microsoft.AspNet.Cors.Test/CorsMiddlewareTests.cs
index 59e693b996..a8906b1f49 100644
--- a/test/Microsoft.AspNet.Cors.Test/CorsMiddlewareTests.cs
+++ b/test/Microsoft.AspNet.Cors.Test/CorsMiddlewareTests.cs
@@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Cors.Test
// Arrange
using (var server = TestServer.Create(app =>
{
- app.UseCors(builder =>
+ app.UseCors(builder =>
builder.WithOrigins("http://localhost:5001")
.WithMethods("PUT")
.WithHeaders("Header1")
@@ -70,8 +70,7 @@ namespace Microsoft.AspNet.Cors.Test
},
services =>
{
- services.AddCors();
- services.ConfigureCors(options =>
+ services.AddCors(options =>
{
options.AddPolicy("customPolicy", policy);
});
@@ -129,7 +128,7 @@ namespace Microsoft.AspNet.Cors.Test
// Arrange
using (var server = TestServer.Create(app =>
{
- app.UseCors(builder =>
+ app.UseCors(builder =>
builder.WithOrigins("http://localhost:5001")
.WithMethods("PUT")
.WithHeaders("Header1")
@@ -156,7 +155,7 @@ namespace Microsoft.AspNet.Cors.Test
[Fact]
public async Task Uses_PolicyProvider_AsFallback()
{
- // Arrange
+ // Arrange
var corsService = Mock.Of();
var mockProvider = new Mock();
mockProvider.Setup(o => o.GetPolicyAsync(It.IsAny(), It.IsAny()))
@@ -184,7 +183,7 @@ namespace Microsoft.AspNet.Cors.Test
[Fact]
public async Task DoesNotSetHeaders_ForNoPolicy()
{
- // Arrange
+ // Arrange
var corsService = Mock.Of();
var mockProvider = new Mock();
mockProvider.Setup(o => o.GetPolicyAsync(It.IsAny(), It.IsAny()))