title: NestJs using same instance of service in multiple modules
body: <p>I have got a NestJs app, that uses two services. The DbService that connects to the Db and the SlowService that does stuff rather slow and uses the injected DbService.</p>
  
  <p>Now the app shall provide health routes outside of the api base path, so i need a different module that provides the controllers for the health routes.</p>
  
  <p>I created a base module.</p>
  
  <pre><code>import { Module } from '@nestjs/common'
  import { SlowService } from './slow.service'
  import { DbService } from './db.service'
  
  @Module({
    imports: [],
    controllers: [],
    providers: [DbService, SlowService],
    exports: [DbService, SlowService]
  })
  export class BaseModule {
  }
  </code></pre>
  
  <p>The ApiModule and the HealthModule now both import the base module to be able to use the services. </p>
  
  <pre><code>  imports: [BaseModule],
  </code></pre>
  
  <p>There is only a small problem. Both modules seem to construct their own instance of the service but I need it to be the same instance. I assume this, because the console.log from the constructor appear twice when starting the app. Am I missing a setting or something?</p>
  
  <p>UPDATE</p>
  
  <p>Here is my bootstrap method, so you can see how I initialize the modules. </p>
  
  <pre><code>async function bootstrap (): Promise&lt;void&gt; {
    const server = express()
    const api = await NestFactory.create(AppModule, server.application, { cors: true })
    api.setGlobalPrefix('api/v1')
    await api.init()
    const options = new DocumentBuilder()
      .setTitle('...')
      .setLicense('MIT', 'https://opensource.org/licenses/MIT')
      .build()
    const document = SwaggerModule.createDocument(api, options)
    server.use('/swaggerui', SwaggerUI.serve, SwaggerUI.setup(document))
    server.use('/swagger', (req: express.Request, res: express.Response, next?: express.NextFunction) =&gt; res.send(document))
    const health = await NestFactory.create(HealthModule, server.application, { cors: true })
    health.setGlobalPrefix('health')
    await health.init()
    http.createServer(server).listen(Number.parseInt(process.env.PORT || '8080', 10))
  }
  const p = bootstrap()
  
  </code></pre>