-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When do you inject vs. just import? (config) #74
Comments
My guess is that the configuration is supposed to be part of the runtime environment and not a dependency. For example, if all your configuration is being imported by dotenv and loaded in the src/config/app.js file, it'd be better to add src/config as a global module resolved by babel. And then in individual services, you could import config like
|
I don’t know if there are any hard and fast rules about this. It is a good question of “where do you draw the line”? I think — since we are talking about global configuration of services that themselves are injected, its idiomatic for config to be an imported module. Because node has a proper module system and imports can be stubbed about as easily as DI services, there isn’t any reason to use DI other than you prefer the semantics. |
My guess is that injecting dependencies is more important when they own resources, but I'm still curious why something like config isn't injected.
The text was updated successfully, but these errors were encountered: