MassTransit states that we should use interfaces for messaging contracts:
It is highly recommended that you use interfaces for messaging contracts based on several years of experience with varying levels of developer experience. MassTransit will create a dynamic message implementation interface, providing a clean separation of the message from the consumer.
Source: MassTransit Usage Documents Creating a Post Contract
What is the disadvantage of using DOC POCO instead of interfaces, what are the obvious advantages of interfaces over classes in the context of messaging with MassTransit?
On the other hand, NServiceBus is great for POCO and, of course, it makes sense not to use internal classes such as a domain object, see below.
Source: NServiceBus Messages Messages, Events, and Commands
When creating messages, you should follow these guidelines:
- Messages must be simple POCO objects.
- Messages should be as small as possible.
- Messages must comply with the principle of single responsibility.
- Classes used for other purposes (for example, domain objects, data access objects, and UI binding objects) should not be used as messages.
source share