using Features.Auth.Identity;
using Features.Auth.Repository;
using Features.Auth.Services;
using Infrastructure.PasswordHashing;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
namespace Features.Auth.DependencyInjection;
/// Registers the services required by Features.Auth with the dependency injection container.
public static class FeaturesAuthServiceCollectionExtensions
{
///
/// Adds , , the Argon2 password hashing
/// infrastructure, and ASP.NET Core Identity ( backed by
/// ) as scoped services.
///
public static IServiceCollection AddFeaturesAuth(this IServiceCollection services)
{
services.AddScoped();
services.AddScoped();
services.AddScoped();
services
.AddIdentityCore(options =>
{
options.User.RequireUniqueEmail = true;
// Password/username complexity is already enforced by RegisterUserValidator
// (FluentValidation); disable Identity's own checks to avoid duplicated/drifting rules.
options.Password.RequireDigit = false;
options.Password.RequireLowercase = false;
options.Password.RequireUppercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequiredLength = 1;
})
.AddDefaultTokenProviders();
services.AddScoped();
services.AddScoped>(sp =>
sp.GetRequiredService()
);
services.AddScoped>(sp =>
sp.GetRequiredService()
);
services.AddScoped>(sp =>
sp.GetRequiredService()
);
services.AddScoped, Argon2PasswordHasher>();
return services;
}
}