Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对于类中注入的许多服务,在angular中使用facade模式是一种好的实践吗?_Angular_Typescript_Dependency Injection_Facade - Fatal编程技术网

对于类中注入的许多服务,在angular中使用facade模式是一种好的实践吗?

对于类中注入的许多服务,在angular中使用facade模式是一种好的实践吗?,angular,typescript,dependency-injection,facade,Angular,Typescript,Dependency Injection,Facade,我有一个动态表单组件,它使用angular DI系统接收许多服务: export class CityFormComponent<DataModel> extends BaseForm<DataModel> implements OnInit { constructor( protected appConfig: AppConfig, protected httpService: CityService, protected snackBar

我有一个动态表单组件,它使用angular DI系统接收许多服务:

export class CityFormComponent<DataModel> extends BaseForm<DataModel> 
implements OnInit {

constructor(
    protected appConfig: AppConfig, 
    protected httpService: CityService,
    protected snackBar: MatSnackBar,
    protected componentFactoryResolver: ComponentFactoryResolver,
    private  cdr: ChangeDetectorRef,
    protected route: ActivatedRoute,
    protected router: Router) { 
          super(appConfig, httpService, snackBar, componentFactoryResolver,              route, router);
}
更改后的基本表单类如下所示:

export abstract class BaseForm<DataModel> implements OnInit, AfterViewInit, OnDestroy {

 constructor(
    protected httpService: BaseService,protected facadeSerivce: FacadeService) {
}

}
导出抽象类BaseForm实现OnInit、AfterViewInit、OnDestroy{
建造师(
受保护的httpService:BaseService,受保护的FacadeService:FacadeService){
}
}
儿童班:

export class CityFormComponent<DataModel> extends BaseForm<DataModel> 
implements OnInit, AfterViewInit, OnDestroy {

constructor(protected httpService: BaseService,protected facadeSerivce: FacadeService) { 
          super(httpService, facadeSerivce);
}
}
导出类CityFormComponent扩展了BaseForm
实现OnInit、AfterViewInit、OnDestroy{
构造函数(受保护的httpService:BaseService,受保护的FacadeService:FacadeService){
super(httpService,facadeservice);
}
}

我的应用程序中有大约50个表单,我想确保将来当我想在基本表单类中添加另一项服务时,我不必更改所有子类构造函数,只需从facade service在基类中添加一个方法,并调用facade service method来使用添加的服务,这样子表单类的其余部分就可以保持不变。
——这就是您需要的全部理由。
export class CityFormComponent<DataModel> extends BaseForm<DataModel> 
implements OnInit, AfterViewInit, OnDestroy {

constructor(protected httpService: BaseService,protected facadeSerivce: FacadeService) { 
          super(httpService, facadeSerivce);
}
}