GithubHelp home page GithubHelp logo

saber-ioc's Introduction

@saber2pr/ioc

a simple Injector for ioc --- 快速的依赖注入IOC容器

兼容 Typescript,es6、es5

# from npm
npm install @saber2pr/ioc

# from github
git clone https://github.com/Saber2pr/saber-ioc.git

关于反射的实现 @saber2pr/reflect

Feature

@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!'

API

  1. @Injectable(id?) 注解一个类作为元数据依赖,若没有提供 id 参数,则默认注册 id 为类名

    注意:请确保 id 是全局唯一的!

  2. @Inject(id) 注解一个依赖到目标类中(从注解参数)

    如果依赖类型是 Interface,请务必提供 Inject 注解。

  3. @InjectProp(id) 注解一个依赖到目标类中(从属性注解)

  4. @Singleton 注册一个类为单例

  5. @Static 注册一个类为静态类

    你可能已经发现这和@Singleton可能是一样的,你是对的

  6. Injector 执行依赖树 build,自动注入实例

    注意保证依赖在注入之前已经声明


start

npm install
npm start

npm run build

npm test

develope and test

you should write ts in /src

you should make test in /src/test


Author

saber2pr


License

MIT

saber-ioc's People

Contributors

saber2pr avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

moeyc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.