// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNet.Cors.Infrastructure; using Microsoft.Extensions.DependencyInjection.Extensions; namespace Microsoft.Extensions.DependencyInjection { /// /// The extensions for enabling CORS support. /// public static class CorsServiceCollectionExtensions { /// /// 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) { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } 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. /// The updated . public static IServiceCollection AddCors( this IServiceCollection serviceCollection, Action configure) { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } if (configure == null) { throw new ArgumentNullException(nameof(configure)); } serviceCollection.Configure(configure); return serviceCollection.AddCors(); } } }