You should only create the maps once during Application_Start
and not use Reset
. For example:
Global.axac.cs
protected void Application_Start()
{
Mapper.Initialize(x => x.AddProfile<ViewProfile>());
}
AutoMapper Configuration
public class ViewProfile : Profile
{
protected override void Configure()
{
Mapper.CreateMap<Word, WordViewModel>();
Mapper.CreateMap<WordViewModel, Word>();
}
}
Make sure you include a unit test to validate your mappings:
[TestFixture]
public class MappingTests
{
[Test]
public void AutoMapper_Configuration_IsValid()
{
Mapper.Initialize(m => m.AddProfile<ViewProfile>());
Mapper.AssertConfigurationIsValid();
}
}
Then just call the Mapper.Map
as required in your application.