This project is no longer being maintained.
Auto discovery of Automapper classes.
- You must have Visual Studio 2019 Community or higher.
- The dotnet cli is also highly recommended.
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);
- Run dotnet restore
- Run dotnet build
- Run dotnet test
Use the package manager NuGet to install Dime.Automapper:
dotnet add package 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>();
};
}
}
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.