I'm encountering an issue with my angular project. These warnings keep popping up:
WARNING in Circular dependency detected:
src\app\core\http\content.service.ts -> src\app\core\http\domain.service.ts ->
src\app\shared\http\domain-shared.service.ts ->
src\app\core\http\content.service.ts
I have three services:
Content Service
where I retrieve codes from my database using the method
getContentCodes()
constructor(
private httpClient: HttpClient,
private tokenService: TokenService,
private domainService: DomainService
) {
this.externalToken = new Token();
this.domainData = this.domainService.getDomainData() as DomainData;
}
Domain Service
where I fetch values either from the instance or storage
constructor(private storageBrowser: StorageBrowser, private domainSharedService: DomainSharedService) {
this.init();
}
getDomainData(): DomainData {
if (this.domainData && Object.values(this.domainData).length > 0) {
return this.domainData;
}
let domain = this.storageBrowser.get(StorageVariables.DOMAIN_DATA);
if (!domain) {
domain = this.checkForDomain();
}
this.domainData = new DomainData(domain);
return this.domainData;
}
setDomainDataItem(item: DomainItem) {
this.domainData.setDomainItem(item);
this.storageBrowser.set(StorageVariables.DOMAIN_DATA, this.domainData, true);
}
async checkForDomain(): Promise<DomainData> {
return await this.domainSharedService.checkDomainData();
}
And lastly, the Domain Shared
service is responsible for making HTTP requests to retrieve Domain Data values
constructor(private clubService: ClubService, private content: ContentService) {
this.domainCalls = [];
}
async checkDomainData(): Promise<DomainData> {
const whiteList: string[] = await this.content.getContentCodes();
const clubLevels: ClubLevel[] = await this.clubService.getClubLevels();
this.domainCalls = [{ code: 'clubLevels', value: clubLevels.reverse() }, { code: 'whiteList', value: whiteList}];
const domainItems: DomainItem[] = this.setItems(this.domainCalls);
const domainData: DomainData = new DomainData();
domainData.data = domainItems;
return domainData;
}
The Content service utilizes the domain service to access the domain shared values which are verified in the domain service where the domain shared service is injected. The Domain Shared service then uses the Content service to obtain the Whitelist through getContentCodes()
Is there a way for these services to communicate with each other without having to inject them or avoid the circular dependency?
Thank you