title: NestJS i18n how to inject service into I18nResolver
body: <p>How can I inject a service into an <code>nestjs-i18n</code> <code>I18nResolver</code>?</p>
  <p>The <a href="https://www.npmjs.com/package/nestjs-i18n#custom-resolver" rel="nofollow noreferrer">docs</a> state that:</p>
  <blockquote>
  <p>To implement your own resolver (or custom logic) use the I18nResolver interface. The resolvers are provided via the nestjs dependency injection, this way you can inject your own services if needed.</p>
  </blockquote>
  <p>My Resolver looks the following:</p>
  <pre class="lang-js prettyprint-override"><code>// AppLanguageResolver.ts
  
  
  import {ExecutionContext, Inject, Injectable, Scope} from &quot;@nestjs/common&quot;;
  import {I18nResolver} from &quot;nestjs-i18n&quot;;
  import {UserService} from &quot;@root/services/user-service/user.service&quot;;
  
  @Injectable()
  export class AppUserLanguageResolver implements I18nResolver {
      constructor(private userService: UserService) {}
  
      resolve(context: ExecutionContext): Promise&lt;string | string[] | undefined&gt; | string | string[] | undefined {
          console.log(&quot;AppUserLanguageResolver&quot;);
          return undefined;
      }
  
  }
  
  </code></pre>
  <p>And in my <code>app.module.ts</code> ive added the module configuration:</p>
  <pre class="lang-js prettyprint-override"><code>// app.module.ts
  
  @Module({
  
    providers: [
      UserService,
      AppUserLanguageResolver,
    ],
    imports: [
      I18nModule.forRoot({
        fallbackLanguage: 'en',
        parser: I18nJsonParser,
        parserOptions: {
          watch: APP_ENV === AppEnv.Dev,
          path: path.join(__dirname, '/i18n/translations'),
        },
        resolvers: [
          AppUserLanguageResolver
        ]
      }),
    ]
  
  });
  
  </code></pre>
  <p>But running the app tells me that nesjs cannot resolve the dependencies:</p>
  <pre><code>[Nest] 5876   - 20/02/2022, 19:21:58   [ExceptionHandler] Nest can't resolve dependencies of the AppUserLanguageResolver (?). Please make sure that the argument UserService at index [0] is available in the I18nModule context.
                                                                                                                                                                                                                                   
  Potential solutions:                                                                                                                                                                                                             
  - If UserService is a provider, is it part of the current I18nModule?                                                                                                                                                            
  - If UserService is exported from a separate @Module, is that module imported within I18nModule?                                                                                                                                 
    @Module({                                                                                                                                                                                                                      
      imports: [ /* the Module containing UserService */ ]                                                                                                                                                                         
    })
   +17ms
  Error: Nest can't resolve dependencies of the AppUserLanguageResolver (?). Please make sure that the argument UserService at index [0] is available in the I18nModule context.
  
  Potential solutions:
  - If UserService is a provider, is it part of the current I18nModule?
  - If UserService is exported from a separate @Module, is that module imported within I18nModule?
    @Module({
      imports: [ /* the Module containing UserService */ ]
    })
  
      at Injector.lookupComponentInParentModules (D:\dev\projects\project\workspace\packages\app-backend\node_modules\@nestjs\core\injector\injector.js:192:19)
      at async Injector.resolveComponentInstance (D:\dev\projects\project\workspace\packages\app-backend\node_modules\@nestjs\core\injector\injector.js:148:33)
      at async resolveParam (D:\dev\projects\project\workspace\packages\app-backend\node_modules\@nestjs\core\injector\injector.js:102:38)
      at async Promise.all (index 0)
      at async Injector.resolveConstructorParams (D:\dev\projects\project\workspace\packages\app-backend\node_modules\@nestjs\core\injector\injector.js:117:27)
      at async Injector.loadInstance (D:\dev\projects\project\workspace\packages\app-backend\node_modules\@nestjs\core\injector\injector.js:81:9)
      at async Injector.loadProvider (D:\dev\projects\project\workspace\packages\app-backend\node_modules\@nestjs\core\injector\injector.js:38:9)
      at async Promise.all (index 15)
      at async InstanceLoader.createInstancesOfProviders (D:\dev\projects\project\workspace\packages\app-backend\node_modules\@nestjs\core\injector\instance-loader.js:43:9)
      at async D:\dev\projects\project\workspace\packages\app-backend\node_modules\@nestjs\core\injector\instance-loader.js:28:13
  
  </code></pre>
  <p><code>UserService</code> is injected in <code>Scope.Request</code> but removing or changing the scopes did not have any effect.
  I also havent found any information regarding this issue.</p>
  <p>How can I fix this?</p>