0.0.4 • Published 1 year ago

@kiyoshiro/ts-wire v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

ts-wire

CI npm version codecov

Features

  • No decorators are needed.
    • You don't need to write any @Injectable.
  • Code-generation based.
    • Good for static checks, fast boot.

https://user-images.githubusercontent.com/40315079/211189731-7b5e876d-8b0c-4d5b-af7e-a85368e85559.mp4

Usage

npm i -D @kiyoshiro/ts-wire
npx ts-wire init # Create `src/wire.ts`

In src/wire.ts, you have to list values and classes you want to resolve dependencies.

import { BarRepository, db, FooController, FooRepository, FooService } from './foo'

export const providers = [db, FooRepository, BarRepository, FooService, FooController]

Then, you run a generate command.

npx ts-wire generate

You can see the following code in src/wire-generated.ts.

import { FooRepository, db, BarRepository, FooService, FooController } from './foo'

const fooRepository = new FooRepository(db)
const barRepository = new BarRepository(db)
const fooService = new FooService(fooRepository, barRepository)
const fooController = new FooController(fooService)
const leaves = { fooController }

export default leaves

Acknowledgments

This library is inspired by https://github.com/google/wire