MapperLibrary.ObjectMapper
1.0.2
dotnet add package MapperLibrary.ObjectMapper --version 1.0.2
NuGet\Install-Package MapperLibrary.ObjectMapper -Version 1.0.2
<PackageReference Include="MapperLibrary.ObjectMapper" Version="1.0.2" />
paket add MapperLibrary.ObjectMapper --version 1.0.2
#r "nuget: MapperLibrary.ObjectMapper, 1.0.2"
// Install MapperLibrary.ObjectMapper as a Cake Addin
#addin nuget:?package=MapperLibrary.ObjectMapper&version=1.0.2
// Install MapperLibrary.ObjectMapper as a Cake Tool
#tool nuget:?package=MapperLibrary.ObjectMapper&version=1.0.2
About Project
This is a simple object mapper project which is written with C#.
The purpose of the project is to map large entity objects to smaller dto objects.
Solution consist of one console, one library and one test project.
Installation
Package can be installed via Package Manager Console with the following command:
Install-Package MapperLibrary.ObjectMapper -Version 1.0.0
Usage
- After installing the nuget package, import MapperLibrary to Startup.cs:
using MapperLibrary.Interfaces;
Then in the ConfigureServices method assign your Entities to DTOs with MapperContainer:
MapperContainer.Assign<Address, AddressDTO>();
MapperContainer.Assign<Employee, EmployeeDTO>();
MapperContainer.Assign<Person, PersonDTO>();
Finally, IMapper interface and Mapper class should be injected to IServiceCollection in the ConfigureServices method:
services.AddScoped<IMapper, Mapper>();
- In the service or controller layer, IMapper can be created and assigned from constructor of related layer like the following:
private readonly IMapper _mapper;
public WeatherForecastController(IMapper mapper)
{
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
}
Then, private _mapper object can map any object to a new instance of assigned type.
Person person = new Person
{
Id = Guid.NewGuid(),
Name = "Test",
Surname = "Test",
BirthDate = DateTime.Now,
IdentityNumber = 12345678901
};
object objectDto = _mapper.Map(person);
PersonDTO personDto = _mapper.Map<PersonDTO>(person);
If destination type is given to Map method, the mapper will return the new object with assigned destination type. In this example, destination type is PersonDTO. If destination type is not assigned, then mapper will return the new object with object type.
Contribution
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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. |
-
net5.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Updated mapper for binding enum properties.