Skip to content

Small dependency injection container for Typescript/JavaScript.

Notifications You must be signed in to change notification settings

gus-messagi/typescuti

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Typescuti

Typescuti is a small dependency injection container for Typescript/JavaScript.

Motivation

There are some other dependency injection libraries, but many of them are decorator's based. There isn't problem with that, however thinking on architecture, our domain layer shouldn't have external dependencies. Through Typescuti, we can inject all dependencies on infrastructure layer.

Installing

Using NPM:

npm install typescuti --save

Or using Yarn:

yarn add typescuti

Usage

// user.service.ts
import { type  User, UserService } from  './user.service'

export  class  UserController {

	// register classes those should be injected
	static  inject  = [UserService]
	
	constructor (private  readonly  service:  UserService) {}

	getUsers ():  User[] {
		return  this.service.getUsers()
	}
}
// user.controller.ts
import  express  from  'express'
import  *  as  container  from  'typescuti'
import { UserController } from  './user.controller'

const  app  =  express()

// resolve classes
const  userController  =  container.resolve<UserController>(UserController)

app.get('/user', (_, res) => {
	const  response  =  userController.getUsers()
	return  res.send(response)
})

app.listen(3333)

Made with 💙 by Gustavo Messagi

About

Small dependency injection container for Typescript/JavaScript.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published