MapperLibrary.ObjectMapper 1.0.2

dotnet add package MapperLibrary.ObjectMapper --version 1.0.2
NuGet\Install-Package MapperLibrary.ObjectMapper -Version 1.0.2
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="MapperLibrary.ObjectMapper" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MapperLibrary.ObjectMapper --version 1.0.2
#r "nuget: MapperLibrary.ObjectMapper, 1.0.2"
#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.
// 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

  1. 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>();
  1. 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

MIT

Project License

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last updated
1.0.2 310 1/8/2022
1.0.0 337 7/6/2021

Updated mapper for binding enum properties.