FunctionSimpleMapper.Extensions 1.0.4

dotnet add package FunctionSimpleMapper.Extensions --version 1.0.4                
NuGet\Install-Package FunctionSimpleMapper.Extensions -Version 1.0.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="FunctionSimpleMapper.Extensions" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FunctionSimpleMapper.Extensions --version 1.0.4                
#r "nuget: FunctionSimpleMapper.Extensions, 1.0.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.
// Install FunctionSimpleMapper.Extensions as a Cake Addin
#addin nuget:?package=FunctionSimpleMapper.Extensions&version=1.0.4

// Install FunctionSimpleMapper.Extensions as a Cake Tool
#tool nuget:?package=FunctionSimpleMapper.Extensions&version=1.0.4                

SimpleMapper

The Simplest mapper possible with DI included. Define the mapper function in once side and use it everywhere

How to use it

You can get the service from the serviceProvider

var mapper = serviceProvider.GetService<ISimpleMapper>();

Or use the interface in your class.

public Controller(ISimpleMapper simpleMapper){
    ...
}

Then you can map the object specifying the source and target class.

var userDto = simpleMapper.Map<User, UserDTO>(user);

or just the source class. You can only set only class using this way.

var userDto = simpleMapper.Map<User>(user);

How to create Mapper classes

Implement the IClassMapper. Then the FunctionSimpleMapper.Extensions will get the binding function.

public class UserMapper : IClassMapper
{
    public void Bind(ISimpleMapper mapper)
    {
        mapper.Bind((User s) => new UserDTO()
            {
                Id = s.Id,
                Name = s.Name,
            });
    }
}

Add the service to de ServiceCollection.

var serviceProvider = new ServiceCollection()
                .AddSimpleMapper() <-- Add this line
                .BuildServiceProvider();
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.4 130 3/5/2024
1.0.3 111 3/4/2024
1.0.2 122 3/4/2024
1.0.1 114 3/4/2024
1.0.0 119 3/4/2024