0

I have a general architectural enquiry about Hot Chocolate. I'm hoping the answer may tell me whether I've made incorrect assumptions or have taken a wrong turn somewhere else.

I am building a simulation system providing stateful generated data for mocking external APIs in a complex distributed system in the energy sector. Each instance of a clustered simulation engine hosts every simulation that is running. One feature of the system is to expose for each simulation a unique GraphQL API providing access to the simulation's generated data (using Hot Chocolate). All data is generated into Azure CosmosDB and repos providing access to each DB are injected into the appropriate Hot Chocolate Web App instance during its initial building stage.

A key point is that at any one time the simulation hosting process is exposing multiple GraphQL APIs on different ports. As a request comes in on a port, I expect the web app exposing that port to have the correct repos injected into it. Instead, I find that regardless of what port/webapp I come in on, the same repos get injected. That is, I always get given the repo for database A, even though I should have been given the repo for database B because I came in on port b.

My question is - is this architecture going to work for me? Is the DI for web apps stored in some kind of static variable? Or is it per web app instance? Should I expect to get the right repo?

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
Andrew Matthews
  • 3,006
  • 2
  • 29
  • 42
  • Have you considered using https://devblogs.microsoft.com/cosmosdb/announcing-data-api-builder-for-azure-cosmos-db/ – Sajeetharan May 04 '23 at 03:38
  • Hi. Nice work! I hadn't heard of this yet. In many cases it would be a good fit, but in others I need to intercept the incoming query then first check Redis and if nothing is found there or in Cosmos then I generate the data being requested. This kind of scaffolding would be ideal if I could also quickly break out into my custom generation code when no data is found in the DB. – Andrew Matthews May 04 '23 at 07:04
  • How are you injecting your stuff? You can find all the docs about injection here: https://chillicream.com/docs/hotchocolate/v13/server/dependency-injection In the HC project I have, I mostly use constructor injection because everything we register is a singleton, which fits with how the class are instantiated in HC. The docs recommend method injection for almost everything. – chrisdrobison May 04 '23 at 14:37

0 Answers0