// 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.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization.Infrastructure; using Microsoft.Extensions.DependencyInjection.Extensions; namespace Microsoft.Extensions.DependencyInjection { /// /// Extension methods for setting up authorization services in an . /// public static class AuthorizationServiceCollectionExtensions { /// /// Adds authorization services to the specified . /// /// The to add services to. /// The so that additional calls can be chained. public static IServiceCollection AddAuthorization(this IServiceCollection services) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.TryAdd(ServiceDescriptor.Transient()); services.TryAdd(ServiceDescriptor.Transient()); services.TryAdd(ServiceDescriptor.Transient()); services.TryAdd(ServiceDescriptor.Transient()); services.TryAdd(ServiceDescriptor.Transient()); services.TryAddEnumerable(ServiceDescriptor.Transient()); return services; } /// /// Adds authorization services to the specified . /// /// The to add services to. /// An action delegate to configure the provided . /// The so that additional calls can be chained. public static IServiceCollection AddAuthorization(this IServiceCollection services, Action configure) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (configure == null) { throw new ArgumentNullException(nameof(configure)); } services.Configure(configure); return services.AddAuthorization(); } } }