title: Using Profiles with nestjsx-automapper in nest.js
body: <p>I´m using <strong>nestjsx-automapper</strong> (<a href="https://automapper.netlify.app/docs/usages/init/add-profile" rel="nofollow noreferrer">https://automapper.netlify.app/docs/usages/init/add-profile</a>) by Chau Tran (thanks for that cool piece of code). I´ve implemented it like shown in the documentation and as already discussed here:
  <a href="https://stackoverflow.com/questions/61429313/how-use-profiles-from-nartc-automapper-into-a-nestjs-application">How use profiles from nartc/automapper into a nestjs application</a></p>
  
  <p>But I still have a <strong>problem to access AutoMapper from within my Profile</strong> class.</p>
  
  <p>Here´s my setup:</p>
  
  <p><strong>app.module.ts:</strong>
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import { Module } from '@nestjs/common';
  import { AppService } from './app.service';
  import { MerchantModule } from './merchant/merchant.module';
  import { TypeOrmModule } from '@nestjs/typeorm';
  import { AutomapperModule, AutoMapper } from 'nestjsx-automapper';
  
  @Module({
    imports: [
      TypeOrmModule.forRoot({
        ...
      }),
      AutomapperModule.withMapper(),
      MerchantModule
    ],
    providers: [],
    controllers: [],
  })
  export class AppModule {}</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>merchant.module.ts:</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import { Module } from '@nestjs/common';
  import { MerchantController } from './merchant.controller';
  import { MerchantService } from './merchant.service';
  import { TypeOrmModule } from '@nestjs/typeorm';
  import { Merchant } from './entities/merchant.entity';
  import { MerchantProfile } from './profiles/merchant.profile';
  import { AutoMapper, AutomapperModule } from 'nestjsx-automapper';
  
  @Module({
    imports: [TypeOrmModule.forFeature([Merchant]), AutomapperModule, MerchantProfile],
    exports: [TypeOrmModule],
    controllers: [MerchantController],
    providers: [MerchantService]
  })
  export class MerchantModule {}</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>merchant.profile.ts:</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import {
    ProfileBase,
    Profile,
    AutoMapper
  } from 'nestjsx-automapper';
  import { Merchant } from '../entities/merchant.entity';
  import { MerchantDto } from '../dto/merchant.dto';
  
  @Profile()
  export class MerchantProfile extends ProfileBase {
    constructor(
      private readonly mapper: AutoMapper) {
      super();
      mapper.createMap(Merchant, MerchantDto);
    }
  
      configure(): void {      
        return null;
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>merchant.controller.ts:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import { Controller, Get, Param, Post, Body, Put, Delete } from '@nestjs/common';
  import { MerchantService } from './merchant.service';
  import { Merchant } from './entities/merchant.entity';
  import { MerchantDto } from './dto/merchant.dto';
  import { DeleteResult } from 'typeorm';
  import { AutoMapper, InjectMapper } from 'nestjsx-automapper';
  
  @Controller('merchant')
  export class MerchantController {
  
      constructor(
          private merchantService: MerchantService,
          @InjectMapper() private readonly mapper: AutoMapper) { }
  
      @Get()
      public async findAll(): Promise&lt;MerchantDto[]&gt; {
          return this.mapper.mapArray(await this.merchantService.find(),MerchantDto);
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>When I run the application with this setup I get the following exception:
  <strong>Nest can't resolve dependencies of the AutomapperModule (?). Please make sure that the argument AutomapperExplorer at index [0] is available in the AutomapperModule context.</strong></p>