// 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.Identity;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Microsoft.Extensions.DependencyInjection
{
///
/// Contains extension methods to for configuring identity services.
///
public static class IdentityServiceCollectionExtensions
{
///
/// Adds and configures the identity system for the specified User type. Role services are not added
/// by default but can be added with .
///
/// The type representing a User in the system.
/// The services available in the application.
/// An for creating and configuring the identity system.
public static IdentityBuilder AddIdentityCore(this IServiceCollection services) where TUser : class
=> services.AddIdentityCore(o => { });
///
/// Adds and configures the identity system for the specified User type. Role services are not added by default
/// but can be added with .
///
/// The type representing a User in the system.
/// The services available in the application.
/// An action to configure the .
/// An for creating and configuring the identity system.
public static IdentityBuilder AddIdentityCore(this IServiceCollection services, Action setupAction)
where TUser : class
{
// Services identity depends on
services.AddOptions().AddLogging();
// Services used by identity
services.TryAddScoped, UserValidator>();
services.TryAddScoped, PasswordValidator>();
services.TryAddScoped, PasswordHasher>();
services.TryAddScoped();
// No interface for the error describer so we can add errors without rev'ing the interface
services.TryAddScoped();
services.TryAddScoped, UserClaimsPrincipalFactory>();
services.TryAddScoped>();
if (setupAction != null)
{
services.Configure(setupAction);
}
return new IdentityBuilder(typeof(TUser), services);
}
}
}