refactor: ai+人工重构优化 framework

This commit is contained in:
橙子
2025-02-23 03:06:06 +08:00
parent f9341fd2ac
commit 3e07ca822a
61 changed files with 2604 additions and 1260 deletions

View File

@@ -8,17 +8,37 @@ using Volo.Abp.ObjectMapping;
namespace Yi.Framework.Mapster
{
/// <summary>
/// Mapster自动对象映射提供程序
/// 实现IAutoObjectMappingProvider接口提供对象间的自动映射功能
/// </summary>
public class MapsterAutoObjectMappingProvider : IAutoObjectMappingProvider
{
/// <summary>
/// 将源对象映射到目标类型
/// </summary>
/// <typeparam name="TSource">源类型</typeparam>
/// <typeparam name="TDestination">目标类型</typeparam>
/// <param name="source">源对象</param>
/// <returns>映射后的目标类型实例</returns>
public TDestination Map<TSource, TDestination>(object source)
{
var sss = typeof(TDestination).Name;
// 使用Mapster的Adapt方法进行对象映射
return source.Adapt<TDestination>();
}
/// <summary>
/// 将源对象映射到现有的目标对象
/// </summary>
/// <typeparam name="TSource">源类型</typeparam>
/// <typeparam name="TDestination">目标类型</typeparam>
/// <param name="source">源对象</param>
/// <param name="destination">目标对象</param>
/// <returns>映射后的目标对象</returns>
public TDestination Map<TSource, TDestination>(TSource source, TDestination destination)
{
return source.Adapt<TSource, TDestination>(destination);
// 使用Mapster的Adapt方法进行对象映射保留目标对象的实例
return source.Adapt(destination);
}
}
}

View File

@@ -7,18 +7,51 @@ using Volo.Abp.ObjectMapping;
namespace Yi.Framework.Mapster
{
/// <summary>
/// Mapster对象映射器
/// 实现IObjectMapper接口提供对象映射功能
/// </summary>
public class MapsterObjectMapper : IObjectMapper
{
public IAutoObjectMappingProvider AutoObjectMappingProvider => throw new NotImplementedException();
private readonly IAutoObjectMappingProvider _autoObjectMappingProvider;
public TDestination Map<TSource, TDestination>(TSource source)
/// <summary>
/// 构造函数
/// </summary>
/// <param name="autoObjectMappingProvider">自动对象映射提供程序</param>
public MapsterObjectMapper(IAutoObjectMappingProvider autoObjectMappingProvider)
{
throw new NotImplementedException();
_autoObjectMappingProvider = autoObjectMappingProvider;
}
/// <summary>
/// 获取自动对象映射提供程序
/// </summary>
public IAutoObjectMappingProvider AutoObjectMappingProvider => _autoObjectMappingProvider;
/// <summary>
/// 将源对象映射到目标类型
/// </summary>
/// <typeparam name="TSource">源类型</typeparam>
/// <typeparam name="TDestination">目标类型</typeparam>
/// <param name="source">源对象</param>
/// <returns>映射后的目标类型实例</returns>
public TDestination Map<TSource, TDestination>(TSource source)
{
return AutoObjectMappingProvider.Map<TSource, TDestination>(source);
}
/// <summary>
/// 将源对象映射到现有的目标对象
/// </summary>
/// <typeparam name="TSource">源类型</typeparam>
/// <typeparam name="TDestination">目标类型</typeparam>
/// <param name="source">源对象</param>
/// <param name="destination">目标对象</param>
/// <returns>映射后的目标对象</returns>
public TDestination Map<TSource, TDestination>(TSource source, TDestination destination)
{
throw new NotImplementedException();
return AutoObjectMappingProvider.Map(source, destination);
}
}
}

View File

@@ -1,21 +1,31 @@
using MapsterMapper;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
using Volo.Abp.ObjectMapping;
using Yi.Framework.Core;
namespace Yi.Framework.Mapster
{
[DependsOn(typeof(YiFrameworkCoreModule),
/// <summary>
/// Yi框架Mapster模块
/// 用于配置和注册Mapster相关服务
/// </summary>
[DependsOn(
typeof(YiFrameworkCoreModule),
typeof(AbpObjectMappingModule)
)]
)]
public class YiFrameworkMapsterModule : AbpModule
{
/// <summary>
/// 配置服务
/// </summary>
/// <param name="context">服务配置上下文</param>
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddTransient<IAutoObjectMappingProvider, MapsterAutoObjectMappingProvider>();
var services = context.Services;
// 注册Mapster相关服务
services.AddTransient<IAutoObjectMappingProvider, MapsterAutoObjectMappingProvider>();
services.AddTransient<IObjectMapper, MapsterObjectMapper>();
}
}
}