MiniMapr.DependencyInjection
1.0.3
This package is deprecated. All functionality has been consolidated into the main MiniMapr package, which now includes Dependency Injection support. Please update your references accordingly.
dotnet add package MiniMapr.DependencyInjection --version 1.0.3
NuGet\Install-Package MiniMapr.DependencyInjection -Version 1.0.3
<PackageReference Include="MiniMapr.DependencyInjection" Version="1.0.3" />
<PackageVersion Include="MiniMapr.DependencyInjection" Version="1.0.3" />
<PackageReference Include="MiniMapr.DependencyInjection" />
paket add MiniMapr.DependencyInjection --version 1.0.3
#r "nuget: MiniMapr.DependencyInjection, 1.0.3"
#:package MiniMapr.DependencyInjection@1.0.3
#addin nuget:?package=MiniMapr.DependencyInjection&version=1.0.3
#tool nuget:?package=MiniMapr.DependencyInjection&version=1.0.3
Using MiniMapr for Object Mapping in .NET
Defining the Source and Target Classes
Suppose you have the following domain and DTO classes:
public class User
{
public string Name { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public Address Address { get; set; }
}
public class UserDto
{
public string Name { get; set; }
public string EmailAddress { get; set; }
public string Password { get; set; } = "";
public AddressDto Address { get; set; }
}
public class Address
{
public string Street { get; set; }
}
public class AddressDto
{
public string Street { get; set; }
}
Creating Mapping Configuration Classes
To define mappings, create classes that implement IMapperConfig. Inside the Configure method, register your mappings using the MapperService instance provided.
Example:
using MiniMapr;
public class UserMappingConfig : IMapperConfig
{
public void Configure(MapperService mapper)
{
mapper.Add<User, UserDto>(config =>
{
config.IgnoredProperties.Add("Password");
config.CustomMappings["Email"] = "EmailAddress";
config.AddCustomTransformation<Address, AddressDto>("Address", address =>
mapper.Map<Address, AddressDto>(address));
});
}
}
public class AddressMappingConfig : IMapperConfig
{
public void Configure(MapperService mapper)
{
mapper.Add<Address, AddressDto>();
}
}
Registering MiniMap in Dependency Injection
To use MiniMapr in a .NET application, register the configuration classes during startup using AddMapper:
var services = new ServiceCollection();
services.AddMapper(mapper =>
{
mapper.Add<UserMappingConfig>()
.Add<AddressMappingConfig>();
});
var serviceProvider = services.BuildServiceProvider();
var mapperService = serviceProvider.GetRequiredService<IMapper>();
Using the Mapper Once registered, you can use the mapper as follows:
var user = new User
{
Name = "Alice",
Email = "alice@email.com",
Password = "secret123",
Address = new Address { Street = "123 Maple St" }
};
var userDto = mapperService.Map<User, UserDto>(user);
Console.WriteLine(userDto.Name); // Alice
Console.WriteLine(userDto.EmailAddress); // alice@email.com
Console.WriteLine(userDto.Password); // (empty)
Console.WriteLine(userDto.Address.Street); // 123 Maple St
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 is compatible. 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.3)
- MiniMapr (>= 1.0.2)
-
net9.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.3)
- MiniMapr (>= 1.0.2)
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.0.3](https://www.github.com/Rael-G/MiniMapr/releases/tag/v1.0.3) (2025-04-06)
### Bug Fixes
* working ci pipeline ([0c4c905](https://www.github.com/Rael-G/MiniMapr/commit/0c4c905bed0eb8052909fdacdc6fceca2eb3729c))
<a name=1.0.2></a>