Skip to content

Commit aadd730

Browse files
authored
Merge pull request #7004 from Particular/record-types
Support for `record` types
2 parents 5f7b269 + 2a393ae commit aadd730

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

nservicebus/messaging/immutable-messages.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Immutable Messages
3-
reviewed: 2024-08-13
3+
reviewed: 2025-02-19
44
component: Core
55
related:
66
- samples/immutable-messages
@@ -13,8 +13,19 @@ Usually messages are designed as [DTOs](https://en.wikipedia.org/wiki/Data_trans
1313
1414
Message objects can be made immutable at runtime by:
1515

16-
1. Creating properties with only public getters and initializing these properties via constructor initialization.
17-
2. Having regular message classes with public getters/setters at the sender, where these classes implement an interface with only public getters. Receivers reference only the interface.
16+
1. Using record types
17+
2. Creating properties with only public getters and initializing these properties via constructor initialization.
18+
3. Having regular message classes with public getters/setters at the sender, where these classes implement an interface with only public getters. Receivers reference only the interface.
19+
20+
21+
## Record types
22+
23+
> [!NOTE]
24+
> Record types are supported starting with NServiceBus 9
25+
26+
```c#
27+
public record CancelOrder(int OrderId);
28+
```
1829

1930
## Properties with only public getters
2031

nservicebus/messaging/messages-events-commands.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ There are checks in place to ensure best practices are followed. Violations of t
4949

5050
Messages should:
5151

52-
* Be simple [POCO](https://en.wikipedia.org/wiki/Plain_old_CLR_object) types
52+
* Be simple [POCOs](https://en.wikipedia.org/wiki/Plain_old_CLR_object) of type `class`, `struct`, or `record`.
5353
* Be as small as possible
5454
* Satisfy the [Single Responsibility Principle](https://en.wikipedia.org/wiki/Single_responsibility_principle)
5555
* Favor simplicity and redundancy over object-oriented practices like inheritance
5656
* Not be re-used for other purposes (e.g., domain objects, data access objects, or UI binding objects)
5757

5858
> [!NOTE]
59-
> Prior to NServiceBus version 7.2, messages had to be defined as a `class`. Defining them as a `struct` would result in a runtime exception.
59+
> - `struct` is supported since 7.2+.
60+
> - `record` is supported since 9.0+.
6061
6162
Generic message definitions (e.g., `MyMessage<T>`) are not supported. It is recommended to use dedicated, simple types for each message.
6263

0 commit comments

Comments
 (0)