I'm having a trouble with my angular project. I'm having these warnings:
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 3 services:
Content Service
where I get a bunch of codes of my DB with 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 have the code to get a values from the instance of this or the 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 finally I have the Domain Shared
service where I will have make the HTTP request to get the 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;
}
Content uses domain service to get the domain shared values that is checked in the domain service where is injected domain shared service. And in this Domain Shared service is injected Content to use getContentCodes() to get the Whitelist
There is a way that I could make this Services communicate each other without having to Inject them or without having the circular dependency?
Thank you