Skip to content

Configuration

Bert Loedeman edited this page Sep 16, 2015 · 4 revisions

Initialization

Initialization is the preferred mode of configuring AutoMapper, and should be done once at application startup:

class CamelCaseToPascalCaseMappingProfile implements AutoMapperJs.IProfile {
    profileName = 'CamelCaseToPascalCase';

    // configuration etc. etc.
}

automapper.initialize((config: AutoMapperJs.IConfiguration) => {
    config.createMap('fromKey', 'toKey');

    config.addProfile(new PascalCaseToCamelCaseMappingProfile());
});

Mapping configuration is static and should not change/be modified.

Naming Conventions

You can set the source and destination naming conventions:

automapper.initialize((config: AutoMapperJs.IConfiguration) => {
  config.sourceMemberNamingConvention = new AutoMapperJs.CamelCaseNamingConvention();
  config.destinationMemberNamingConvention = new AutoMapperJs.PascalCaseNamingConvention();
});

This will map the following properties to each other: propertyName -> PropertyName

You can also set this at a per profile level

class CamelCaseToPascalCaseMappingProfile implements AutoMapperJs.IProfile {
    profileName = 'CamelCaseToPascalCase';

    public configure() {
        sourceMemberNamingConvention = new AutoMapperJs.CamelCaseNamingConvention();
        destinationMemberNamingConvention = new AutoMapperJs.PascalCaseNamingConvention();
    }
}

Samples

Some samples are already created. You can run the configuration samples: