1 | # Decorators
|
2 |
|
3 | Both [event handlers](EventHandlers.md)
|
4 | and [command handlers](CommandHandlers.md) work
|
5 | with [TypeScript decorators][decorators]. These identify values that
|
6 | will be injected into a fresh instance each time the handler runs. If
|
7 | you're familiar with Spring, this will be particularly intuitive.
|
8 |
|
9 | [decorators]: https://www.typescriptlang.org/docs/handbook/decorators.html (TypeScript Decorators)
|
10 |
|
11 | Consider the following code within a command handler:
|
12 |
|
13 | ```typescript
|
14 | @Parameter({
|
15 | displayName: "Desired Spring Boot version",
|
16 | description: "The desired Spring Boot version across these repos",
|
17 | pattern: /^.+$/,
|
18 | validInput: "Semantic version",
|
19 | required: false,
|
20 | })
|
21 | public desiredBootVersion: string = "1.5.6.RELEASE";
|
22 | ```
|
23 |
|
24 | The value of the `desiredBootVersion` parameter (if provided) will be
|
25 | injected into an instance before the `handle` function is called.
|
26 |
|
27 | The decorated variable names the parameter. If you assign a value to
|
28 | the variable, as in the example, it becomes the parameter’s default
|
29 | value.
|