- No decorators are needed.
- You don't need to write any
@Injectable
.
- You don't need to write any
- Code-generation based.
- Good for static checks, fast boot.
demo.mp4
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
This library is inspired by https://github.com/google/wire