dependency injection特征

dependency injection依赖注入

特征:

  • Type & Metadata Annotations类型和元数据注释
  • Scope/Lifetime作用域/生命周期
  • Child Injectors子注入
  • More...更多

//元数据类型构造函数type metadata from constructor

MyComponent.parameters = [{is:Server}];

//元数据注释

MyComponent.annotate = [new Inject(Server)];

//使用任何对象作为令牌

MyComponent.annotate = [new Inject('my-string-token')];

//声名对象的生命周期和作用域

@TransientScope

export class MyClass{ ... }

原文地址:https://www.cnblogs.com/cjxhd/p/5152695.html