explicit-di
TypeScript icon, indicating that this package has built-in type declarations

1.4.2 • Public • Published

explicit-di

Usage:

// composition root file

import { component, systemMap, using } from 'explicit-di'
import { loggerComponent } from '@logger'
import { messagingComponent } from '@messaging'

const componentMap = {
  logger: loggerComponent,
  messaging: using(
    messagingComponent,
    deps: ['logger']
  )
}
// @logger
import { FancyLogger } from 'fancy-logger-tool'
import { component } from 'explicit-di'

const loggerClient = new FancyLogger()

export const loggerComponent = component(() => loggerClient)
// @messaging
import { subscribe } from 'fancy-messaging-tool'
import { ILogger } from '@interfaces'
import { component } from 'explicit-di'

interface Deps {
  logger: ILogger
}

class MessagingClient {
  unsubscribe?: () => {}

  start: ({ logger }: Deps) => {
    logger.logMessage('Start Listening')
    this.unsubscribe = subscribe()
  }

  stop: () => {
    if (this.unsubscribe) this.unsubscribe()
  }
}

const messagingClient = new MessagingClient()

export const messagingComponent = component(
  messagingClient.start,
  messagingClient.stop
)

Readme

Keywords

none

Package Sidebar

Install

npm i explicit-di

Weekly Downloads

15

Version

1.4.2

License

MIT

Unpacked Size

29.1 kB

Total Files

15

Last publish

Collaborators

  • sichacvah