# from npm
npm install @saber2pr/ioc
# from github
git clone https://github.com/Saber2pr/saber-ioc.git
@Injectable()
class Service {
public getUser() {
return 'saber!'
}
}
class Controller {
public constructor(@Inject('Service') private Service: Service) {}
// @InjectProp() private Service: Service
public test() {
console.log(this.Service.getUser())
}
}
const app = Injector(Controller)
app.test() // 'saber!'
@Injectable(id?) id id
`` id
@Inject(id) ()
Interface Inject
@InjectProp(id) ()
@Singleton
@Static
@Singleton
Injector build
``
npm install
npm start
npm run build
npm test
you should write ts in /src
you should make test in /src/test
saber2pr
MIT