Unexpected Database Connection Creation with Layer Configuration
So, I'm all in with "service dependencies are an implementation detail". However, I am seeing some behavior that I'm not liking.
I'm defining all my services with a layer with all their dependencies fulfilled, including the database service, that includes a database connection.
They look like this:
Then I join them all and give them to my runtime:
Just for being sure I added a log line to the database effect constructor:
What I see in the logs is that line appearing from time to time. My guess is that each time a service that has that layer is used, then the corresponding database service is created. Isn't this supposed to be cached?
To be clear, I'm not seeing on every request, for example, I only see when I go to parts of the application that require a service that was not yet used, but sometimes it just happens again for "areas" that in theory were already loaded. Am I doing something wrong?
I'm defining all my services with a layer with all their dependencies fulfilled, including the database service, that includes a database connection.
They look like this:
Then I join them all and give them to my runtime:
Just for being sure I added a log line to the database effect constructor:
What I see in the logs is that line appearing from time to time. My guess is that each time a service that has that layer is used, then the corresponding database service is created. Isn't this supposed to be cached?
To be clear, I'm not seeing on every request, for example, I only see when I go to parts of the application that require a service that was not yet used, but sometimes it just happens again for "areas" that in theory were already loaded. Am I doing something wrong?
