Merge pull request 'main' (#32) from main into feature-nxdev

Reviewed-on: #32
This commit is contained in:
2025-12-29 21:57:33 +08:00
committed by nanxun
16 changed files with 780 additions and 268 deletions
@@ -1,5 +1,9 @@
using IM_API.Interface.Services;
using IM_API.Dtos;
using IM_API.Interface.Services;
using IM_API.Services;
using IM_API.Tools;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
namespace IM_API.Configs
{
@@ -7,6 +11,7 @@ namespace IM_API.Configs
{
public static IServiceCollection AddAllService(this IServiceCollection services, IConfiguration configuration)
{
services.AddAutoMapper(typeof(MapperConfig));
services.AddTransient<IAuthService, AuthService>();
services.AddTransient<IUserService, UserService>();
@@ -14,8 +19,28 @@ namespace IM_API.Configs
services.AddTransient<IMessageSevice, MessageService>();
services.AddTransient<IConversationService, ConversationService>();
services.AddSingleton<IJWTService, JWTService>();
services.AddSingleton<IRefreshTokenService,RedisRefreshTokenService>();
services.AddSingleton<IRefreshTokenService, RedisRefreshTokenService>();
return services;
}
}
public static IServiceCollection AddModelValidation(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<ApiBehaviorOptions>(options =>
{
options.InvalidModelStateResponseFactory = context =>
{
var errors = context.ModelState
.Where(e => e.Value.Errors.Count > 0)
.Select(e => new
{
Field = e.Key,
Message = e.Value.Errors.First().ErrorMessage
});
return new BadRequestObjectResult(new BaseResponse<object?>(CodeDefine.PARAMETER_ERROR.Code, errors.First().Message));
};
});
return services;
}
}
}