/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit/Initializers/HeaderInitializers/SetStringHeaderInitializer.cs
41 строка
1 KB
Chris Patterson
Integration of all external packages into MassTransit, split out into Abstractions, Middleware, and the core MassTransit assembly.
22 янв 2022, 18:24
22 янв 2022, 18:24
b5b4f50
Код
Авторство
О чём код?
namespace MassTransit.Initializers.HeaderInitializers { using System; using System.Reflection; using System.Threading.Tasks; using Internals; /// <summary> /// Set a header to a constant value from the input /// </summary> /// <typeparam name="TMessage"></typeparam> /// <typeparam name="TInput"></typeparam> public class SetStringHeaderInitializer<TMessage, TInput> : IHeaderInitializer<TMessage, TInput> where TMessage : class where TInput : class { readonly string _headerName; readonly IReadProperty<TInput, string> _inputProperty; public SetStringHeaderInitializer(string headerName, PropertyInfo propertyInfo) { if (headerName == null) throw new ArgumentNullException(nameof(headerName)); _headerName = headerName; _inputProperty = ReadPropertyCache<TInput>.GetProperty<string>(propertyInfo); } public Task Apply(InitializeContext<TMessage, TInput> context, SendContext sendContext) { var inputPropertyValue = _inputProperty.Get(context.Input); sendContext.Headers.Set(_headerName, inputPropertyValue); return Task.CompletedTask; } } }