You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
summary: Custom conventions for defining how certain things are detected
3
+
summary: Custom conventions for defining how certain things are detected and to support unobtrusive mode
4
4
component: Core
5
-
reviewed: 2021-10-04
5
+
reviewed: 2024-08-22
6
6
related:
7
7
- nservicebus/messaging/messages-events-commands
8
8
- nservicebus/messaging/unobtrusive-mode
9
9
---
10
10
11
-
A *convention* is a way of defining what a certain type is instead of using an interface or an attribute. Using conventions along with avoiding references to NServiceBus assemblies is referred to as *[unobtrusive mode](unobtrusive-mode.md)*. This is ideal for use in cross-platform environments.
11
+
*Conventions* can be used to identify which types are messages, commands, and events, instead of using [marker interfaces](/nservicebus/messaging/messages-events-commands#identifying-messages-marker-interfaces). This can be done to avoid references to the NServiceBus assembly, referred to as *[unobtrusive mode](unobtrusive-mode.md)*. This is ideal for use in cross-platform environments.
Messages can be defined in a *Portable Class Library* (PCL) and shared across multiple platforms even if the platform does not use NServiceBus for message processing.
22
+
Message types can be defined in a *Portable Class Library* (PCL) and shared across multiple platforms, even if the platform does not use NServiceBus for message processing.
23
23
24
24
snippet: MessageConventions
25
25
26
26
> [!NOTE]
27
-
> Note that in .NET, the namespace is optional and hence can be null. If any conventions do partial string checks, for example using `EndsWith` or `StartsWith`, then a null check should be used. So include `.Namespace != null` at the start of the convention. Otherwise a null reference exception will occur during the type scanning.
27
+
> In .NET, the namespace is optional and can be null. If any conventions do partial string checks, for example using `EndsWith` or `StartsWith`, then a null check should be used. Include `.Namespace != null` at the start of the convention to avoid a null reference exception during type scanning.
28
28
29
29
## Using both default and custom conventions
30
30
31
-
Defining conventions will replace any of the existing conventions. If both default and custom conventions are needed it is required to embed the NServiceBus marker interfaces/types into the new custom conventions.
31
+
Defining a custom convention will overwrite the default convention. If both default and custom conventions are needed, the default conventions must be specified along with the custom conventions.
32
32
33
33
snippet: MessageConventionsDual
34
34
35
35
partial: encapsulated-conventions
36
36
37
37
## Attributes
38
38
39
-
If attributes are preferred over marker interfaces then this can be achieved via[NServiceBus.AttributeConventions](https://github.com/mauroservienti/NServiceBus.AttributeConventions), a [community package](/nservicebus/community/) that allows using attributes instead of interfaces.
39
+
If attributes are preferred over marker interfaces then this can be achieved using[NServiceBus.AttributeConventions](https://github.com/mauroservienti/NServiceBus.AttributeConventions), a [community package](/nservicebus/community/) that allows using attributes instead of interfaces.
0 commit comments