AutoMapper add Profile on assembly load
11,394
It seems your Mapper.AddProfile
is not calling when the application starts.
Try this,
In Global.asax.cs
[Application_Start
],
protected void Application_Start(object sender, EventArgs e)
{
Mapper.AddProfile<MyProfile>();
}
And MyProfile
looks like below,
public class MyProfile : Profile
{
public override string ProfileName
{
get { return "Name"; }
}
protected override void Configure()
{
//// BL to DL
Mapper.CreateMap<BLCLASS, DLCLASS>();
//// and DL to BL
Mapper.CreateMap<DLCLASS, BLCLASS>();
}
}
Author by
Nisha_Roy
Updated on June 14, 2022Comments
-
Nisha_Roy almost 2 years
I want to register all the Mappings in my Business Layer to Data Layer, and Data Layer to Business Layer classes just as my Business Layer assembly loads. Currently I am using a static class to do this task for me:
public static class AutoMapperBootstrapper { public static void InitMappings() { Mapper.Initialize(a => a.AddProfile<MyProfile>()); } }
But each time I make a call with Mapper.Map and the added mappings in the profile, it is still saying Missing Type Mapping Information.
How I should go about fixing this?