-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Feat: lazy-loading-modules-like
based on user input
#1048
Comments
Like any other nest application, nest will create the modules specified by the You can create a secondary |
By your answer, I understand that the logic of loading modules based on the user inputs are already exist. Right? |
What do you mean here by "based on the user inputs"? Inputs from the person running the CLI, or inputs from the dev? Technically, they're both possible, one just takes more work |
Let's say, for example, that the user trigger the command install. In that case, I would like to have the ability to split the install command off the other commands with a new module, which will be initialized with all its dependencies without the other modules. input: 'my-cli install ts-node'
With that input, just the install module will be initialized. |
Technically, yes it's possible depending on how you decide to write it all up. Again, nest-commander doesn't actually do any of the module instantiation, it's just a wrapper around You could check for which arg was passed before calling I think most of this logic though is out of the hands of |
I thought the same, although it'll be super convenient to just activate that by a flag. |
@Avivbens how the API to this would look like? |
I thought about something like this: 2 Commands as an example @Command({
name: 'shell',
options: { isDefault: false },
})
export class ShellCommand extends CommandRunner {
constructor(
private readonly logger: LoggerService,
) {
super()
this.logger.setContext(ShellCommand.name)
}
}
@Command({
name: 'install',
options: { isDefault: false },
})
export class InstallCommand extends CommandRunner {
constructor(
private readonly logger: LoggerService,
) {
super()
this.logger.setContext(InstallCommand.name)
}
} The lazy loading module @Module({
providers: [LoggerService, CheckUpdateService, ShellCommand, InstallCommand],
// new API
isLazy: true,
})
export class ShellModule implements OnModuleInit {
constructor(
private readonly checkUpdateService: CheckUpdateService,
){ }
onModuleInit() {
/* would trigger by one of the following commands:
- cli shell
- cli install
*/
console.log('Module has been initialized, due to triggering one of the commands of the module.')
this.checkUpdateService.check()
}
} |
@Avivbens introducing that flag to Instead, we should find a way to use what nestjs already have: the lazy loading modules features |
Well, could be We also need to understand how we can register modules based on that (best is the understand which command related to which module). |
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
Currently, all lifecycles like
onModuleInit
,onModuleDestroyed
, etc, are been triggered just likeonApplicationBootstrap
.In that way, we cannot control events to happen in some scenarios like triggering a few commands, signing requests, etc.
In addition, we're initializing the entire application, instead of just what the CLI needs to operate for this input.
Describe the solution you'd like
The ability to configure lazy loading modules, which reduce the load time of the CLI and initialize just the needed code, based on the user input to the CLI.
Teachability, documentation, adoption, migration strategy
No response
What is the motivation / use case for changing the behavior?
The text was updated successfully, but these errors were encountered: