Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register multiple serializers for outgoing messages #7070

Open
ramonsmits opened this issue Jun 17, 2024 · 0 comments
Open

Register multiple serializers for outgoing messages #7070

ramonsmits opened this issue Jun 17, 2024 · 0 comments

Comments

@ramonsmits
Copy link
Member

ramonsmits commented Jun 17, 2024

Is your feature related to a problem? Please describe.

Currently you cannot send a message and use a specific serializer. All outgoing messages are serialized in the same format. For native integration is can be very useful to serialize messages to different endpoints using different formats.

Describe the requested feature

Ability to register multiple SERIALIZERS (so not deserializers as these are already supported) and have methods to use a specific serializer based on convention, a specific message type, custom rule or sendoption.

Convention

However, it might also require a convention as the type could in an assembly now in control of the user.

var serializer = endpointConfiguration.UseSerialization<XmlSerializer>();
serializer.Match(type => type.NameSpace.StartsWith("ServiceX");

SendOption

var sendOptions = new SendOptions();
sendOptions.ContentType("application/json; systemjson");

Attribute

A good candidate would be to have a default serializer as we currently have but have the ability to specify a specific one an attribute:

[ContentType("text/xml")]
public MyCommand
{
}

// Ability to register multiple JSON serializers
[ContentType("application/json; systemjson")]
public MyCommand
{
}

[ContentType("application/json")]
public MyOtherCommand()
{
}

Registrations

var serializer = endpointConfiguration.UseSerialization<XmlSerializer>("text/xml"); // Not specifying would use the default content type key:

It would potentially just be nice if all serializers would be DI registered and can be resolved via a keyed service:

var jsonSerializer = // ..
services.AddKeyedSingleton<IMessageSerializer, JsonMessageSerializer>(jsonSerializer.ConentType);
var xmlSerializer = // ..
services.AddKeyedSingleton<IMessageSerializer, JsonMessageSerializer>(xmlSerializer.ContentType);

Describe alternatives you've considered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant