Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 841 Bytes

custom-decorator.md

File metadata and controls

36 lines (27 loc) · 841 Bytes

Using your own decorator

Create your own decorator to avoid coupling your inner architecture layers with DIOD. It does not need to do anything, but without decorators Typescript won't emit constructor metadata.

export const MyAppService = (): ClassDecorator => {
  return <TFunction extends Function>(target: TFunction): TFunction => {
    return target
  }
}

Use it on your services:

import { MyAppService } from './my-app-service'

@MyAppService()
export class MyService {
  constructor(/* ... */) {}

  //...
}

Register your services in the normal way:

import { ContainerBuilder } from 'diod'
// Other imports...

const builder = new ContainerBuilder()
builder.registerAndUse(MyService)
// ...
export const container = builder.build()