// 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.Authorization;
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.
/// A reference to this instance after the operation has completed.
public static IServiceCollection AddAuthorization(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
services.AddOptions();
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 .
/// A reference to this instance after the operation has completed.
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();
}
}
}