Angular

Integrate DynamicMapper into your Angular application

DynamicMapper provides mini library for basic integration with Angular framework.

Install

npm i @dynamic-mapper/angular --save

Import MapperModule and profile providers

Add your mapping profiles via MapperModule.withProviders.

import { MapperModule } from '@dynamic-mapper/angular';

@NgModule({
    imports: [
        MapperModule.withProfiles([CustomerProfile, OrderProfile])
    ]
})
export class AppModule {}

Inject mapper service

Inject mapper service from @dynamic-mapper/angular package. This mapper instance has configured all registered profiles from MAPPING_PROFILE provider.

import { Mapper } from '@dynamic-mapper/angular';

@Injectable()
export class CustomerService {
    constructor(private readonly mapper: Mapper) {}
    
    toDto(customer: Customer) {
        return this.mapper.map(CustomerProfile.DomainToDto, customer);
    }
}

Last updated