-
-
Notifications
You must be signed in to change notification settings - Fork 286
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
Register configuration programmatically #2379
Comments
Hello @borjapazr
attach a configuration to a provider and can be used on any module or injectable class. Attached configuration to a provider are resolved and consumed by the DI before loading all providers. PlatformExpress.boostrap() Is the first place where you can add settings. It let developers to fetch a configuration on remote server before loading the Server itself. Adding a registerConfiguration has no sense for me, because it won't be attached to a provider, it will cause probably a side effect on how the configuration must be merge with the main configuration. "register at any time" isn't a good idea when it's related to a server configuration. See you |
Hello, @Romakita. I understand, it is perfectly clear. Thank you very much for your answer. Best regards! |
@Romakita is it possible to invoke some ConfigService before using My idea is to have ConfigService which loads some json file, env vars,... and handles all the configuration (server config, and other stuff not important on server startup). I have a workaround, there is a DI independent class which I instantiate before Thanks! |
You can load your settings and pass fetched configuration as parameter into platform bootstrap function. import {$log} from "@tsed/common";
import {PlatformExpress} from "@tsed/platform-express";
import {Server} from "./server";
async function bootstrap() {
try {
// TODO: fetch your config files here
$log.debug("Start server...");
const platform = await PlatformExpress.bootstrap(Server, {
// pass your fetched extra settings here
});
await platform.listen();
$log.debug("Server initialized");
} catch (er) {
$log.error(er);
}
}
bootstrap(); |
I know, that's what I'm doing. but I would like to use ConfigService before Currently my ConfigService is DI independent, thus testing is not ideal. I would like to use other services inside ConfigService. You know one for loading json configuration, another for ENV vars,... |
Why do you need to complexify that… just load your config on index.ts and then use your services. ConfigService must stay simple. If you need other services isn’t normal. it is no longer a configure service but a node bag ^^ |
Is there any way to set the configuration programmatically similar to the way providers are registered with
registerProvider(...)
? For example, something similar toThe motivation for this is to be able to register a configuration at any time without having to use the
@Configuration({...})
annotation when you define the server or thePlatformExpress.bootstrap(Server, <configuration_here>)
function.Thanks in advance 🙏
The text was updated successfully, but these errors were encountered: