Is there anyways to prevent a service from being injected outside of its original module?
Say that we're loading the projects.module.ts lazily and ProjectsModule is importing the ProjectsStoreModule. I have a service defined in ProjectsStoreModule that I don't want to be injected in the ProjectsModule, but it's ok to be injected anywhere inside the ProjectsStoreModule. I was wondering if there's a way to achieve this?
Note: ProjectsStoreModule does not have any Components so I can't provide the service to a component. The service that I want to be isolated is going to be injected in an Ngrx Effect which is a service.
What I did:
I registered the ProjectsService:
@Injectable({
providedIn: ProjectsStoreModule
})
export class ProjectsService {
...
}
ProjectsModule:
@NgModule({
...
})
export class ProjectsModule {
...
imports: [ProjectsStoreModule]
}
This approach obviously caused so many Circular dependency warnings.
Then I tried to register the ProjectsService in the @NgModule decorator:
@NgModule({
...
providers: [ProjectsService]
})
export class ProjectsStoreModule {
...
}
Now the problem is that, by importing the ProjectsStoreModule into the ProjectsModule, the service that I wanted to be an internal service will be available in the ProjectsModule.
Any help would be highly appreciated.