Shipeng.Mapster
4.1.1
dotnet add package Shipeng.Mapster --version 4.1.1
NuGet\Install-Package Shipeng.Mapster -Version 4.1.1
<PackageReference Include="Shipeng.Mapster" Version="4.1.1" />
<PackageVersion Include="Shipeng.Mapster" Version="4.1.1" />
<PackageReference Include="Shipeng.Mapster" />
paket add Shipeng.Mapster --version 4.1.1
#r "nuget: Shipeng.Mapster, 4.1.1"
#:package Shipeng.Mapster@4.1.1
#addin nuget:?package=Shipeng.Mapster&version=4.1.1
#tool nuget:?package=Shipeng.Mapster&version=4.1.1
Shipeng.Mapster
Shipeng.Mapster 是基于 Mapster 的对象映射集成包,提供对象映射工具和 DI 注册扩展。它适合 DTO、ViewModel、Command、Entity 之间的转换,避免每个项目重复配置 Mapster。
安装
dotnet add package Shipeng.Mapster
适用场景
- Entity 转 DTO、DTO 转 ViewModel、Command 转 Entity。
- 希望通过 DI 使用统一的对象映射服务。
- 多项目需要复用 Mapster 扫描和配置方式。
主要类型
MapperTool:轻量反射映射辅助工具,适合同名同类型属性之间的快速复制;内部缓存属性映射关系,避免每次映射重复反射扫描。ObjectMapperServiceCollectionExtensions:Mapster 服务注册扩展入口,扩展方法为AddObjectMapper(this IServiceCollection services, params Assembly[] assemblies)。MapsterMapper.IMapper:调用AddObjectMapper后可从 DI 容器注入使用的 Mapster 映射服务。
基本用法
using MapsterMapper;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
// 注册 Mapster 映射服务;assemblies 用于扫描实现 Mapster.IRegister 的映射配置。
builder.Services.AddObjectMapper(typeof(Program).Assembly);
var app = builder.Build();
app.Run();
在业务服务中注入 IMapper:
using MapsterMapper;
public sealed class UserAppService
{
private readonly IMapper _mapper;
public UserAppService(IMapper mapper)
{
_mapper = mapper;
}
public UserDto ToDto(UserEntity entity)
{
return _mapper.Map<UserDto>(entity);
}
}
如果只是做同名同类型属性复制,也可以直接使用 MapperTool:
using Shipeng.Foundation.Mapster;
UserDto dto = entity.Mapper<UserDto, UserEntity>();
entity.Mapper(existingDto);
List<UserDto> dtoList = entities.ListToList<UserDto, UserEntity>();
使用建议
- 简单字段名一致的映射可直接使用默认约定。
- 字段名不一致、需要格式化、需要忽略敏感字段时,应显式配置映射规则。
- 不要在循环中重复创建映射配置,配置应在应用启动时完成。
- 大批量映射要注意对象分配成本,必要时使用投影查询减少内存压力。
MapperTool只复制公开实例属性,且要求属性名忽略大小写后相同、属性类型完全相同;索引器、只读属性、Error、Item不会被复制。
API Reference / API 索引
nuget.org 当前只会直接渲染包的 README 和 Release Notes,不会把包内 docs/API_REFERENCE.md 自动显示成一个独立页面标签。完整公开 API 索引已经随 NuGet 包打入 docs/API_REFERENCE.md,也可以在源码仓库中查看。
如果你正在 NuGet 页面阅读本文,请优先看本 README 的“主要类型”和示例;下载包后可在包内容中打开 docs/API_REFERENCE.md 查看完整公开类型、方法、属性和构造函数签名。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Mapster (>= 10.0.10)
- Mapster.DependencyInjection (>= 10.0.10)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Shipeng.Mapster:
| Package | Downloads |
|---|---|
|
Shipeng.Data.Hybrid
Hybrid MongoDB and SqlSugar paging helper package for read-model scenarios that query MongoDB first and fall back to SQL data when needed. |
GitHub repositories
This package is not used by any popular GitHub repositories.
4.1.1 / 2026-06-30
English:
- Split the original monolithic foundation library into focused Shipeng.* NuGet packages so applications can reference only the capabilities they actually need.
- Added Shipeng.DatabaseMaintenance for SQL Server and MongoDB database maintenance. It supports non-destructive cleanup preview, SqlSugar entity scanning, MongoDB collection scanning from configuration or source declarations, keep lists, ignored prefixes, empty-scan protection, missing table preview, controlled SqlSugar CodeFirst table creation, SQL Server schema difference preview, safe missing-column creation, safe changed-column synchronization, explicit execution switches, and confirmation-code protected destructive/schema-changing execution.
- Improved Shipeng.Payment with a unified payment abstraction for WeChat, Alipay, UnionPay, Cloud QuickPass, bank gateways, and profit-sharing scenarios. WeChat Pay V3 remains the concrete built-in implementation; other channels expose stable provider contracts and explicit placeholders so applications can add real vendor SDK implementations without changing business code.
- Centralized common NuGet metadata in Directory.Build.props: target framework, version, authors, repository, license, README, XML documentation, warning policy, and release notes.
- Every package includes README.md, XML IntelliSense documentation, and docs/API_REFERENCE.md inside the generated nupkg.
- Updated README files to explain that nuget.org renders README and Release Notes directly but does not expose packaged docs/API_REFERENCE.md as a separate page tab.
- Release build validation: all projects build and pack successfully for net10.0 with 0 warnings and 0 errors.
中文:
- 将早期单体基础库拆分为职责更清晰的 Shipeng.* NuGet 包,业务项目可以按需引用认证、MongoDB、SqlSugar、EF Core、数据库索引、数据库维护、第三方集成、日志、映射、支付和混合分页能力。
- 新增 Shipeng.DatabaseMaintenance,用于 SQL Server 和 MongoDB 数据库维护。支持冗余表/集合预览清理、SqlSugar 实体扫描、MongoDB 配置集合扫描、源码集合声明扫描、保留名单、忽略前缀、空扫描保护、缺失表预览、受控 CodeFirst 自动建表、SQL Server 结构差异预览、缺失字段补齐、安全字段同步、显式执行开关和确认码保护。
- 增强 Shipeng.Payment,新增统一支付抽象,覆盖微信、支付宝、银联、云闪付、银行网关和分账场景。微信支付 V3 是当前内置可用实现;其他通道提供稳定 Provider 契约和明确占位实现,方便业务项目接入真实厂商 SDK。
- 将公共 NuGet 元数据统一集中到 Directory.Build.props,避免各项目 PropertyGroup 重复和不一致。
- 每个包都打入 README.md、XML IntelliSense 文档和 docs/API_REFERENCE.md。
- 所有 README 都补充说明:nuget.org 会直接显示 README 和 Release Notes,但不会把包内 docs/API_REFERENCE.md 自动显示为独立标签页。
- 已验证 Release 构建和打包,目标框架 net10.0,0 警告,0 错误。