Context and EntryPoint¶
Context¶
-
initializeContext
(contextInfo)¶ Initializes the context used to create the application in. This includes a custom entrypoint, list of providers, and if a custom entryPoint is not provided the name and version of the program.
Arguments: - contextInfo (ContextInitialization) – Info used to initialize the context with.
Returns: Runnable – The EntryPoint with which to run the program.
-
class
ContextInitialization
()¶ interface, exported from
ommander-mv
Info used when initializing the context in which the program will run.
-
ContextInitialization.
entryPoint
¶ type: Constructor
Specify a custom entrypoint.
-
ContextInitialization.
name
¶ type: undefined | string
The name of the program. Should not be specified if using a custom entrypoint.
-
ContextInitialization.
providers
¶ type: InjectionRegistrationKey[]
List of providers, including all controllers and exception filters. Providers listed here will be available for dependency injection throughout the rest of the program.
-
ContextInitialization.
version
¶ type: undefined | string
The version of the program. Should not be specified if using a custom entrypoint.
-
EntryPoint¶
-
EntryPoint
(metaInfo)¶ Creates an EntryPoint decorator.
Arguments: - metaInfo (MetaInfo) – Meta info about the program. Includes the program name and version.
Returns: (Anonymous function) – The decorator used to designate the class as a custom entrypoint.
Note
A custom interface must inject cliService and call cliService.parse in
the run method. The Runnable()
interface can be used to help remember
to specify a run method.
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | @EntryPoint({
name: 'context-example',
version: '1.0.0'
})
export class Program {
constructor ({ cliService }) {
this.cliService = cliService
}
run(argv) {
this.cliService.parse(argv)
}
}
const customProvider = provide('customProvider', { /* ... */ })
initializeContext({
entryPoint: Program,
providers: [
AccountService,
AccountController,
ConfigService,
customProvider
]
})
|