Skip to content

Aliasing

Mauro Gadaleta edited this page Jan 10, 2020 · 1 revision

Aliasing

You may sometimes want to use shortcuts to access some services.

import Mailer from './Mailer'
import {ContainerBuilder} from 'node-dependency-injection'

let container = new ContainerBuilder()
container.register('service.mailer', Mailer)

container.setAlias('mailer', 'service.mailer')

This means that when using the container directly, you can access the service.mailer service by asking for the mailer service like this:

container.get('mailer')

In YAML, you can also use a shortcut to alias a service:

services:
    # ...
    mailer: '@service.mailer'

or JSON

{
  "services": {
    // ...
    "mailer": "@service.mailer"
  }
}

or JS

module.exports = {
    services: {
        // ...
        mailer: "@service.mailer"
    }
}