SyZero.AutoMapper
1.1.4
dotnet add package SyZero.AutoMapper --version 1.1.4
NuGet\Install-Package SyZero.AutoMapper -Version 1.1.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SyZero.AutoMapper" Version="1.1.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.AutoMapper" Version="1.1.4" />
<PackageReference Include="SyZero.AutoMapper" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SyZero.AutoMapper --version 1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyZero.AutoMapper, 1.1.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SyZero.AutoMapper@1.1.4
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SyZero.AutoMapper&version=1.1.4
#tool nuget:?package=SyZero.AutoMapper&version=1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SyZero.AutoMapper
SyZero 框架的 AutoMapper 集成模块,提供对象映射自动配置。
📦 安装
dotnet add package SyZero.AutoMapper
✨ 特性
- 🚀 自动扫描 - 自动扫描并注册所有 Profile
- 💾 依赖注入 - 无缝集成 Microsoft DI
- 🔒 类型安全 - 编译时类型检查
🚀 快速开始
1. 配置 appsettings.json
{
"AutoMapper": {
"AssembliesToScan": ["MyApp.Application"]
}
}
2. 注册服务
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// 添加SyZero
builder.AddSyZero();
// 注册服务方式1 - 自动扫描当前程序集
builder.Services.AddSyZeroAutoMapper();
// 注册服务方式2 - 指定程序集
builder.Services.AddSyZeroAutoMapper(typeof(UserProfile).Assembly);
// 注册服务方式3 - 多个程序集
builder.Services.AddSyZeroAutoMapper(
typeof(UserProfile).Assembly,
typeof(OrderProfile).Assembly
);
var app = builder.Build();
// 使用SyZero
app.UseSyZero();
app.Run();
3. 使用示例
public class UserProfile : Profile
{
public UserProfile()
{
CreateMap<User, UserDto>();
CreateMap<CreateUserInput, User>();
}
}
public class UserService
{
private readonly IMapper _mapper;
public UserService(IMapper mapper)
{
_mapper = mapper;
}
public UserDto GetUser(User user)
{
return _mapper.Map<UserDto>(user);
}
}
📖 配置选项
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
AssembliesToScan |
string[] |
[] |
要扫描的程序集名称 |
📖 API 说明
IMapper 接口
| 方法 | 说明 |
|---|---|
Map<TDestination>(source) |
将源对象映射到目标类型 |
Map<TSource, TDestination>(source, dest) |
映射到现有对象 |
Map(source, sourceType, destType) |
动态类型映射 |
所有映射操作都是线程安全的
🔧 高级用法
自定义值转换
public class UserProfile : Profile
{
public UserProfile()
{
CreateMap<User, UserDto>()
.ForMember(dest => dest.FullName,
opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}"));
}
}
条件映射
CreateMap<User, UserDto>()
.ForMember(dest => dest.Email,
opt => opt.Condition(src => src.IsEmailVerified));
⚠️ 注意事项
- Profile 类 - 所有映射配置应在 Profile 类中定义
- 循环引用 - 注意处理对象间的循环引用
- 性能 - 避免在热路径中使用动态映射
📄 许可证
MIT License - 详见 LICENSE
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- AutoMapper (>= 9.0.0)
- AutoMapper.Collection (>= 6.0.0)
- AutoMapper.Extensions.Microsoft.DependencyInjection (>= 7.0.0)
- SyZero (>= 1.1.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.4 | 31 | 1/2/2026 |
| 1.1.4-dev.2 | 35 | 1/2/2026 |
| 1.1.4-dev.1 | 35 | 12/30/2025 |
| 1.1.3 | 73 | 12/30/2025 |
| 1.1.3-dev.6 | 34 | 12/30/2025 |
| 1.1.3-dev.3 | 101 | 1/19/2024 |
| 1.1.3-dev.2 | 169 | 11/3/2023 |
| 1.1.3-dev.1 | 181 | 3/21/2023 |
| 1.1.2 | 371 | 3/15/2023 |
| 1.1.2-dev.108.29344 | 183 | 3/15/2023 |
| 1.1.2-dev.108.28054 | 172 | 3/15/2023 |
| 1.1.2-dev.108.27487 | 178 | 3/15/2023 |
| 1.1.1 | 312 | 3/15/2023 |
| 1.1.1-dev.108.14980 | 179 | 3/15/2023 |
| 1.1.1-dev.108.13289 | 176 | 3/15/2023 |
| 1.1.1-dev.107.27144 | 172 | 3/14/2023 |
| 1.1.0 | 328 | 3/14/2023 |
| 1.1.0-workflow-dev.107.22552 | 175 | 3/14/2023 |
| 1.1.0-workflow-dev.107.21746 | 173 | 3/14/2023 |
| 1.1.0-workflow-dev.107.21506 | 167 | 3/14/2023 |
| 1.1.0-workflow-dev.107.20979 | 172 | 3/14/2023 |
| 1.1.0-dev.107.26364 | 170 | 3/14/2023 |
| 1.1.0-dev.107.24396 | 174 | 3/14/2023 |
| 1.1.0-dev.107.22787 | 173 | 3/14/2023 |
| 1.0.6 | 607 | 3/5/2022 |
| 1.0.4 | 638 | 6/13/2020 |
| 1.0.1 | 649 | 2/20/2020 |
| 1.0.0 | 670 | 11/5/2019 |