Я пытаюсь добавить дочерние сервисы в родительский сервис, добавив декоратор класса в провайдер и добавив родительский сервис, однако, когда я перезаписываю конструктор декорированного класса, получая родительский сервис как неопределенный, даже пытался использовать defineMetada Reflect-Metdata с безуспешно, ниже приведен фрагмент кода.
Служба родителей
@Injectable({
providedIn: 'root'
})
export class ParentService {
constructor() {
}
}
класс экспорта MyClass {
constructor () {
console.log (называется MyClass);
}
}
Сервисный конфигуратор
здесь я пытаюсь добавить дочерние службы
@ServiceConfig({
services: [MyClass]
})
@Injectable({
providedIn: AppModule
})
export class AppService extends ServiceProvider {
constructor(parent: ParentService) {
super(parent);
console.log('app service');
console.log(parent);
}
}
Сервисный прводер
export class ServiceProvider {
constructor(private _parent: PService) {
console.log('base', this._parent); // <-- here getting parent is undefined
}
public init(services: any[]) {
console.log('init',services);
}
}
Класс декоратора
здесь пытается переопределить конструктор
export function ServiceConfig(parameter: any) {
return function (target: any) {
const original = target;
const decoratedConstructor: any = function (...args: any[]): void {
console.log('Before original', args);
original.apply(this, args);
console.log('After original');
};
decoratedConstructor.prototype = original.prototype;
// Copy static members too
Object.keys(original).forEach((name: string) => { decoratedConstructor[name] = (<any>original)[name]; });
return decoratedConstructor;
};
}