0

Ive two entities: EntityA and EntityB. EntityA need selectors from EntityB in order to compose a new one. Then, on EntityB we need selectors from EntityA in order to compose a new one. That generates a circular dependency error.

Whats the best aproach to solve the problem? Yeah, i know i can move the dependent selectors to the same Entity<>.selectors file but i dont like it. I've thought about creating a file that only contains common selectors between entities.

Daniel Heras
  • 33
  • 1
  • 5

1 Answers1

0

you can't have cross dependencies, one of them will be undefined in runtime.

To solve the issue you need to create a new file with a new service class / selectors, where you inject both entities as dependencies so they don't depend on each other anymore.

An example how to do it you can find here: https://ngrx-entity-relationship.sudo.eu/help/circular-dependency in the Troubleshooting section.

satanTime
  • 12,631
  • 1
  • 25
  • 73
  • Can you be a bit more specific about which file(s) demonstrate the solution? I’m running into the same problem. – daudihus Feb 17 '21 at 22:44
  • Something like that https://github.com/satanTime/nx-nestjs-angular-graphql/blob/master/apps/ct-frontend/src/app/entity/store/selectors.ts – satanTime Feb 18 '21 at 06:09