Proper way to initialize config
See original GitHub issueI’m submitting a…
[ ] Regression [ ] Bug report [ ] Feature request [x] Documentation issue or request [ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
There is nothing but a short snippet about a “configServiceProvider” in the documentation:
const configServiceProvider = {
provide: ConfigService,
useClass: DevelopmentConfigService,
};
@Module({
components: [configServiceProvider],
})
Expected behavior
One article describing how to properly create a ConfigService provider which loads variables from the .env file, including validation (for example: is port actually a number between 1 and 65535?) and usage in other components.
It could easily be added to one of the examples showing how to pass database credentials for example.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:19
- Comments:43 (11 by maintainers)
Top Results From Across the Web
Python Initialization Configuration — Python 3.11.1 ...
Python can be initialized with Py_InitializeFromConfig() and the PyConfig structure. It can be preinitialized with Py_PreInitialize() and the PyPreConfig ...
Read more >Correct way to initialize settings in .net core 2.2?
Now to initialize GlobalSettings I used configure method in startup class like this. using (var scope = app.ApplicationServices.CreateScope()) { ...
Read more >Chapter 7. Application Configuration and Initialization
The Struts initialization process reads, initially, the struts-config.xml file (also in the config directory) in order to determine how URL's are mapped to ......
Read more >Initializing the Configuration - Revenera Product Documentation
The createConfig() method must be called in order to initialize the configuration. The createConfig() method creates a configuration for the SDK instance.
Read more >How to Fix "Configuration System Failed to Initialize" Error in ...
How to Fix " Configuration System Failed to Initialize " Error in Windows Computer.Some users reported that Configuration system failed to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Creating new abstractions like modules dependent on providers directly might create too much mess. However, I fully understand your concerns, the possibility to pass options asynchronously is a very essential thing. Thus, I just published new versions of both
@nestjs/typeorm
and@nestjs/mongoose
modules. They exposeforRootAsync()
method now, which give various ways to initialize the configuration object.1. Use factory
Obviously, our factory behaves like every other one (might be
async
and is able to inject dependenciesinject
).2. Use class
Above construction will instantiate
MongooseConfigService
insideMongooseModule
and will leverage it to create options object.3. Use existing
It works the same as
useClass
with one critical difference -MongooseModule
will lookup imported modules to reuse already createdConfigService
, instead of instantiating it on its own.The internal implementation is quite simple. Everyone who is interested in that should check the repositories to see how it is achieved underneath.
@cdiaz thanks. And now how do I pass a config variable to dynamic module in
the forRoot()
method?