Files
IM_NEW/User.WebApi/Program.cs

61 lines
2.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using IM.InitCommon.Management;
using IdentityService.Domain.Entities;
using IdentityService.Infrastructure;
using IM.InitCommon;
using Microsoft.AspNetCore.Identity;
namespace IdentityService.WebApi
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.ConfigureDbConfiguration();
builder.ConfigExtraServices();
// 2. 🌟 微软 Identity 终极注册组合拳
builder.Services.AddIdentityCore<User>(options =>
{
// 这里可以顺手配置一下密码规则,比如不需要大写字母、最小长度等
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequiredLength = 6;
})
.AddRoles<Role>()
.AddEntityFrameworkStores<UserDbContext>() // 👈 灵魂所在:自动向 DI 注入 IUserStore<User> 等几十个底层接口!
.AddUserManager<IdUserManager>() // 👈 告诉框架:不要用你默认的 UserManager,用我自定义的 IdUserManager
.AddRoleManager<RoleManager<Role>>()
.AddDefaultTokenProviders(); // 👈 顺带注册生成验证码/重置密码Token的服务
builder.Services.AddAllGrpcServer();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.ApplyMigrationsIfRequested(args)) return;
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseAppDefault();
app.MapManagementHealth();
app.MapControllers();
app.MapAllGrpcServer();
app.Run();
}
}
}