A resolve service is being implemented using the new providedIn
attribute.
This translations resolver is utilized in a protected module:
import { Injectable } from '@angular/core';
import { Observable , pipe } from 'rxjs';
import {map} from "rxjs/operators";
//This causes: "WARNING in Circular dependency detected:"
import {ProtectedModule} from "../../../protected/protected.module";
import { HttpHandlerService } from '../../http/http-handler.service';
@Injectable({
providedIn: ProtectedModule //The import for this line is required
})
export class TranslationsResolverService {
constructor(private _httpHandlerService : HttpHandlerService) { }
resolve(): any {
//Do Something...
}
}
The translations resolver service is declared in the protected routing module:
import { NgModule } from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {AuthGuard} from "../core/resolvers/auth/auth.guard";
import {TranslationsResolverService} from "./../core/resolvers/translations/translations-resolver.service";
const routes: Routes = [
{
path : 'app' ,
component: ProtectedComponent,
resolve : {
translations : TranslationsResolverService
},
canActivate: [AuthGuard],
]
}
];
@NgModule({
imports : [RouterModule.forChild(routes)],
exports : [RouterModule]
})
export class ProtectedRoutingModule { }
About importing the protected.module
in the translations-resolver.service.ts
to use it in the providedIn
attribute, it triggers a WARNING about Circular dependency:
path/to/translations-resolver.service.ts ->
protected/protected.module.ts ->
protected/protected-routing.module.ts ->
path to translations-resolver.service.ts
The extra path (protected/protected.module.ts) is added due to the providedIn
attribute.
To remedy this issue, the translationsResolver
can be provided as an NgModule provider
(in the providers array), but preference is towards it being an injectable
provider.
Any suggestions on how to solve this?