automapper Profiles Loading all profiles in an assembly

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Often it is useful to be able to load all of the profiles in one or more assemblies into a configuration. AutoMapper provides the method AddProfiles method, which has several overloads that allow profiles to be loaded by passing the Assembly, specifying the assembly name, or specifying a type contained in the assembly. Only classes inheriting from AutoMapper.Profile will be located and added to the configuration.

Load all profiles in an assembly by specifying the name of the assembly:

Mapper.Initialize(cfg => {
    cfg.AddProfiles("MyApplication.Core", "MyApplication.Web");
});

Load all profiles in an assembly by specifying a type from the assembly:

Mapper.Initialize(cfg => {
    cfg.AddProfiles(typeof(Student), typeof(Course));
});

Load all profiles in the current assembly:

Mapper.Initialize(cfg => {
    cfg.AddProfiles(Assembly.GetExecutingAssembly());
});


Got any automapper Question?