Repository navigation
Publish/Send should pass declared producer message type (Produce<T>) even if sending derived message type - #445
Merged
Conversation
zarusz
force-pushed
the
feature/DeclaredProducerTypeInSerializer
branch
from
November 28, 2025 10:17
1feafaf to
a8ad9e7
Compare
…even if sending derived message type Signed-off-by: Tomasz Maruszak <maruszaktomasz@gmail.com>
zarusz
force-pushed
the
feature/DeclaredProducerTypeInSerializer
branch
from
November 28, 2025 10:19
a8ad9e7 to
2ab2771
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Restoring v2 Serialization Behavior in v3
This PR reintroduces the serialization behavior from SlimMessageBus v2 to ensure backward compatibility:
MessageTypeofProducer<T>(), even when a derived message type was published.Changes included in this PR:
Note on Serialization with Polymorphic Messages:
When publishing a derived message type (e.g.,
CustomerCreatedEvent) with only the base type configured (e.g.,Produce<CustomerEvent>), the serializer'sSerializemethod will receive the configured type from theProduce<T>()declaration (i.e.,CustomerEvent), not the actual runtime type (CustomerCreatedEvent). This allows serializers to maintain consistent type information in headers and ensures proper polymorphic behavior.However, if you explicitly declare
Produce<CustomerCreatedEvent>()for the derived type, the serializer will receiveCustomerCreatedEventinstead. SMB will use the most specific matching producer configuration available for each message type.This behavior applies to both single message publishing via
Publish()and bulk publishing with collections of messages.