Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Issue Multiple Services usage #68

Closed
kevin-madhu opened this issue Nov 16, 2016 · 5 comments
Closed

Issue Multiple Services usage #68

kevin-madhu opened this issue Nov 16, 2016 · 5 comments

Comments

@kevin-madhu
Copy link

imports: [
  ...
  InMemoryWebApiModule.forRoot(Service1), // "app/service1"
  InMemoryWebApiModule.forRoot(Service2) // "app/service2"
]

When in-memory-web-api is used for multiple services like this, only the last service url(not checked with more than 3, so I dunno if "last" is always true) is available. I confirmed it by switching places of service1 and service2.

@psamsotha
Copy link

All you need to do is add multiple collections to the returned object in the createDb method

createDb() {
  let service1 = [];
  let service2 = [];
  return { service1, service1 }
}

This gives you access to

/app/service1
/app/service1/1
/app/service2
/app/service2/1

I think some people get confused by the syntax in all the example(s)

return { heroes }

This is the same (shorthand) as

return { heroes: heroes }

So each property in the returned object is considered a collection. So if you have multiple collections, just add more properties. Each property is the collection URL. e.g.

return {
  heroes: heroes     // app/heroes
  crises: crises     // app/crises
}

Or the shorthand

return { heroes, crises }

@kevin-madhu
Copy link
Author

The method I mentioned used to work earlier. Anyways, thanks :)

@eranSinger
Copy link

This is a solution in case you're looking for one inMemoryDB to rule them all.
Let me complicate things:
We're using ng6 modules and we want each module to be independent from the rest, while having it's own inMemoryDB.
in that case i cannot have multiple collections at the same DB and only the last module is triggered when the app sends a rest call. (each mock service passThruBackaned in case it does not know how to handle).

any suggestions how to handle that?
thanks

@willmcf
Copy link

willmcf commented Feb 7, 2019

This is a solution in case you're looking for one inMemoryDB to rule them all.
Let me complicate things:
We're using ng6 modules and we want each module to be independent from the rest, while having it's own inMemoryDB.
in that case i cannot have multiple collections at the same DB and only the last module is triggered when the app sends a rest call. (each mock service passThruBackaned in case it does not know how to handle).

any suggestions how to handle that?
thanks

I have the the same problem. How to have multiple modules each with their own inMemoryDB.

@viktorv
Copy link

viktorv commented Apr 8, 2020

Any updates on this issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants