项目作者: makeflow

项目描述 :
A minimal solution of dependency injection for projects that scale.
高级语言: TypeScript
项目地址: git://github.com/makeflow/entrance-decorator.git
创建时间: 2020-02-21T02:41:13Z
项目社区:https://github.com/makeflow/entrance-decorator

开源协议:MIT License

下载


Entrance Decorator

A minimal solution of dependency injection for projects that scale.

Why

🙂

Installation

  1. yarn add entrance-decorator

Usage

Define entrances

  1. import {entrance} from 'entrance-decorator';
  2. export class Entrances {
  3. constructor(private url: string) {}
  4. @entrance
  5. get uiService() {
  6. return new UIService(this.errorService);
  7. }
  8. @entrance
  9. get errorService() {
  10. return new ErrorService({
  11. baseURL: this.url,
  12. });
  13. }
  14. }

Extend/override entrances

  1. import {entrance} from 'entrance-decorator';
  2. export class MobileEntrances extends Entrances {
  3. // Extend entrance
  4. @entrance
  5. get mobileService() {
  6. return new MobileService(this.errorService);
  7. }
  8. // Override entrance
  9. @entrance
  10. get uiService() {
  11. return new MobileUIService(this.errorService);
  12. }
  13. }

Use entrances

  1. const entrances = new Entrances('https://makeflow.com');

You may use the entrances object in whatever way you want. For example, we use Context in React (in a decorator manner) and use something like entrances.launchServer() in server-side applications.

What it does

Cache and circular dependency check, nothing else.

License

MIT License.