当基类和继承类都被标记为`@Service()`装饰器时,**属性**就支持继承性。在创建时,继承有装饰属性的类将收到这些属性上的初始化类实例。
```
import 'reflect-metadata';
import { Container, Token, Inject, Service } from 'typedi';
@Service()
class InjectedClass {
name: string = 'InjectedClass';
}
@Service()
class BaseClass {
name: string = 'BaseClass';
@Inject()
injectedClass: InjectedClass;
}
@Service()
class ExtendedClass extends BaseClass {
name: string = 'ExtendedClass';
}
const instance = Container.get(ExtendedClass);
// instance的`name`属性带有 "ExtendedClass "值(覆盖了基类)
// `injectedClass`属性为`InjectedClass`类的实例
console.log(instance.injectedClass.name);
// 输出"InjectedClass"
console.log(instance.name);
// 输出 "ExtendedClass"
```