/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit/Configuration/SetSerializerSendConventionExtensions.cs
52 строки
2 KB
Chris Patterson
Fixed #4240 - Added ability to specify message type specific serialization content type
29 мар 2023, 21:35
29 мар 2023, 21:35
a907378
Код
Авторство
О чём код?
namespace MassTransit { using System; using System.Net.Mime; using Configuration; public static class SetSerializerSendConventionExtensions { /// <summary> /// Use the message serializer identified by the specified content type to serialize messages of this type /// </summary> /// <typeparam name="T">The message type</typeparam> /// <param name="configurator"></param> /// <param name="contentType"></param> public static void UseSerializer<T>(this IMessageSendTopologyConfigurator<T> configurator, ContentType contentType) where T : class { configurator.AddOrUpdateConvention<ISetSerializerMessageSendTopologyConvention<T>>( () => { var convention = new SetSerializerMessageSendTopologyConvention<T>(); convention.SetSerializer(contentType); return convention; }, update => { update.SetSerializer(contentType); return update; }); } /// <summary> /// Use the message serializer identified by the specified content type to serialize messages of this type /// </summary> /// <typeparam name="T">The message type</typeparam> /// <param name="configurator"></param> /// <param name="contentType"></param> public static void UseSerializer<T>(this IMessageSendTopologyConfigurator<T> configurator, string contentType) where T : class { if (contentType == null) throw new ArgumentNullException(nameof(contentType)); var type = new ContentType(contentType); UseSerializer(configurator, type); } } }