[Question] Possible to initialize with configuration (or any other injected service) and how are environment variables parsed?
See original GitHub issueAs far as I can tell, there are two options to initialize Drivine:
- From environment variables
- From values set using a fluent API
From this, I get two questions:
-
How are environment variables parsed? In the docs, it shows the method
DatabaseRegistry.buildOrResolveFromEnv('NEO')
. What is'NEO'
in this case? EDIT:
After digging through the Drivine code, I found that the environment variables are hardcoded and prefixed with the name given (NEO
, in this case), resulting in environment variables being forced to take the nameNAME_DATABASE_TYPE
. Using a configuration package which uses environment variables could conflict with this naming (as it does in my case).
Specifying howbuildOrResolveFromEnv
works in the docs might clear things up a bit. I can submit a PR later if you would like me to. -
Is there a way to inject configuration (or anything in Nest’s DI tree) into the module initialization?
Nest provides dynamic modules, being able to use DI. Is there a way to use that with Drivine as well?
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (4 by maintainers)
@Bastianowicz What you can do in the meantime is inject the factory instead, like this:
I reproduced the issue you folks are having on a current project. It occurs when:
And above is how I worked around that for now.
Thank you for the quick response. I was updating my question as you were typing 😃
Indeed it does use env vars. As I mentioned in the updated question,
ConnectionProperties#ConnectionPropertiesFromEnv
usesprocess.env
already, so both approaches will work just fine.Yes, to bootstrap it dynamically. For example, Nest’s GraphQL library uses a factory to allow for DI to work, simply by injecting anything into the factory method. This can inject, for example, a configuration service. A similar approach could be taken here:
Where
config
would be injected.I mention doing it this way, as my configuration package has separators to parse environment variables to config classes, making it incompatible with Drivine’s way of using environment variables.
I’m not sure how to approach this. Perhaps you could point me in the right direction?