Building API with Express: Injecting Request-Scoped Services
I've been building an API with Michael's excellent example of Express integration here: Using Effect to Control Scopes
It's going really well, but I've been stuck trying to figure out how to inject services that only exist for the life of a request.
Specifically, my problem is that I have a TodoService which depends on the DatabaseConnection service (which depends on a DatabaseConnectionPool service). The DatabaseConnection has a scope of the life of the request. I want to be able to be able to provide the implementation of TodoService at AppLive, but it because it depends on the DatabaseConnection service, that ends up as a dependency of AppLive.
Additionally, I'd like to be able to avoid supplying a DatabaseConnection if I mock the TodoService, but that's only relevant once I've solved the first part.
Does anyone have any suggestions for how to model this?
It's going really well, but I've been stuck trying to figure out how to inject services that only exist for the life of a request.
Specifically, my problem is that I have a TodoService which depends on the DatabaseConnection service (which depends on a DatabaseConnectionPool service). The DatabaseConnection has a scope of the life of the request. I want to be able to be able to provide the implementation of TodoService at AppLive, but it because it depends on the DatabaseConnection service, that ends up as a dependency of AppLive.
Additionally, I'd like to be able to avoid supplying a DatabaseConnection if I mock the TodoService, but that's only relevant once I've solved the first part.
Does anyone have any suggestions for how to model this?
