NGRX Data - Providing multiple EntityCollectionReducerMethodsFactory classes to Module

244 Views Asked by At

Following the documentation for additional collection state, I have been able to make it work with only one entity collection. In the module I am building I am using three entity collections so far. I'm not sure how the injection in the module should be done but this is what I am doing:

  providers: [
    {
      provide: EntityCollectionReducerMethodsFactory,
      useClass: ExtendedPharmaCollectionReducerMethodsFactory,

    },
    {
      provide: EntityCollectionReducerMethodsFactory,
      useClass: ExtendedClnicalCollectionReducerMethodsFactory
    },
    {
      provide: EntityCollectionReducerMethodsFactory,
      useClass: ExtendedUsersCollectionReducerMethodsFactory
    }
  ]

The above approach is not working. What I've noticed is that the last provider is overring the top two. For example, in the above example, the injected service that works is the ExtendedUsersCollectionReducerMethodsFactory. If I change the order like this:

  providers: [
    {
      provide: EntityCollectionReducerMethodsFactory,
      useClass: ExtendedClnicalCollectionReducerMethodsFactory
    },
    {
      provide: EntityCollectionReducerMethodsFactory,
      useClass: ExtendedUsersCollectionReducerMethodsFactory
    },
    {
      provide: EntityCollectionReducerMethodsFactory,
      useClass: ExtendedPharmaCollectionReducerMethodsFactory,

    }
  ]

Then the one that works is the ExtendedPharmaCollectionReducerMethodsFactory. My question is the following....

How can I provide different EntityCollectionReducerMethodsFactory for different entity collections?

0

There are 0 best solutions below