Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Latest commit

 

History

History
116 lines (81 loc) · 2.99 KB

README.md

File metadata and controls

116 lines (81 loc) · 2.99 KB

Dime.Automapper

Build Status Dime.AutoMapper package in Dime.Scheduler feed in Azure Artifacts

This project is no longer being maintained.

Introduction

Auto discovery of Automapper classes.

Getting Started

  • You must have Visual Studio 2019 Community or higher.
  • The dotnet cli is also highly recommended.

About this project

The purpose of this project was to reach automatic discovery of mapping classes through reflection. This has been addressed in AutoMapper 9, eliminating the need of this project.

Dime.Automapper:

public static void Main(params string[] args)
{
    AutoMapperFactory.Initialize();

    IMapper mapper = AutoMapperFactory.Create();
    TestClassOne instance1 = new TestClassOne() { Id = 2 };
    TestClassTwo instance2 = mapper.Map<TestClassTwo>(instance1);
}

public class TestClassMapper : IAutoMapper
{
    public Action<IMapperConfigurationExpression> Configure()
    {
        return (x) =>
        {
            x.CreateMap<TestClassOne, TestClassTwo>();
        };
    }
}

AutoMapper 9:

internal sealed class ClientMapper : AutoMapper.Profile
{
    /// <summary>
    /// Initializes a new instance of the <see cref="ClientMapper"/> class
    /// </summary>
    public ClientMapper()
    {        
        CreateMap<Client, ClientDto>();
    }
}

MapperConfiguration configuration = new MapperConfiguration(cfg =>
{
    cfg.AddMaps("My.Library");
    cfg.DisableConstructorMapping();
});

var mapper = new Mapper(configuration);

Build and Test

  • Run dotnet restore
  • Run dotnet build
  • Run dotnet test

Installation

Use the package manager NuGet to install Dime.Automapper:

dotnet add package Dime.Automapper

Usage

public static void Main(params string[] args)
{
    AutoMapperFactory.Initialize();

    IMapper mapper = AutoMapperFactory.Create();
    TestClassOne instance1 = new TestClassOne() { Id = 2 };
    TestClassTwo instance2 = mapper.Map<TestClassTwo>(instance1);
}

public class TestClassMapper : IAutoMapper
{
    public Action<IMapperConfigurationExpression> Configure()
    {
        return (x) =>
        {
            x.CreateMap<TestClassOne, TestClassTwo>();
        };
    }
}

Contributing

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

License