我有一个现有服务,它是一个服务集合,使用名称为EFFECTS
的不透明令牌注册。本质上,该服务只是一组共享相同接口的子服务。
对于每个EFFECTS
服务,我想将EffectsModule
导入AppModule
并将每个服务注入EffectsModule.run()
方法。
请参阅以下内容:
import { NgModule } from '@angular/core';
import { Actions, EffectsModule } from '@ngrx/effects';
import { SharedModule } from '../shared/shared.module';
import { Account, User } from './models';
import { AccountEffects, UserEffects } from './effects';
import { ApiService } from '../core/services/api.service';
import { EFFECTS } from './tokens';
@NgModule({
imports: [
SharedModule,
{
// HOW??
useFactory: (effects) => effects.map(effect => EffectsModule.run(effect)),
deps: [EFFECTS],
}
],
providers: [
{
provide: EFFECTS,
useClass: UserEffects,
useFactory: (Actions, ApiService) => new AccountEffects(Actions, ApiService, Account),
multi: true,
deps: [Actions, ApiService]
},
{
provide: EFFECTS,
useClass: UserEffects,
useFactory: (Actions, ApiService) => new UserEffects(Actions, ApiService, User),
multi: true,
deps: [Actions, ApiService]
},
],
})
export class AppModule { }
是否可以这样做?