Angular | Replace a service in the inner modules by a other class

Viewed 140

Here is the full declaration of the nested module

https://github.com/abpframework/abp/blob/16db5036c2d8bd74b238f0855bf9e509bf6ef956/npm/ng-packs/packages/core/src/lib/core.module.ts

the source file we have three declared modules

//BaseCoreModule
@NgModule({
...
   import:[
    ...
    OAuthModule, // has the service that I want to replace by my own
    ...
   ]
...
})
export class BaseCoreModule {}
//RootCoreModule
@NgModule({
  exports: [BaseCoreModule, LocalizationModule],
  imports: [
    BaseCoreModule,//notice 
    ...
    OAuthModule.forRoot(), // OAuthModule is imported again using forRoot()
    ...
  ],
})
export class RootCoreModule {}
// CoreModule will be imported to the AppModule
@NgModule({
  exports: [BaseCoreModule],
  imports: [BaseCoreModule],
})
export class CoreModule {
  static forRoot(options = {} as ABP.Root): ModuleWithProviders<RootCoreModule> {
    return {
      ngModule: RootCoreModule,
      providers: [...other providers...]
    }
   }
  }

The CoreModule is imported in my AppModule using forRoot() function. What I want to do is to replace (override) a service provided in the OAuthModule which is deeply imported by the CoreModule without the necessity to use conventional methods (e.g. using source code instead of npm lib)

0 Answers
Related