/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/Transports/MassTransit.EventHubIntegration/EventHubIntegrationExtensions.cs
50 строк
2 KB
denys.kozhevnikov
Separate scoped ConsumeContext through components
23 май 2023, 23:32
23 май 2023, 23:32
e679624
Код
Авторство
О чём код?
namespace MassTransit { using System; using DependencyInjection; using EventHubIntegration.Configuration; using Microsoft.Extensions.DependencyInjection; public static class EventHubIntegrationExtensions { public static void UsingEventHub(this IRiderRegistrationConfigurator configurator, Action<IRiderRegistrationContext, IEventHubFactoryConfigurator> configure) { if (configurator == null) throw new ArgumentNullException(nameof(configurator)); var factory = new EventHubRegistrationRiderFactory(configure); configurator.SetRiderFactory(factory); configurator.TryAddScoped<IEventHubRider, IEventHubProducerProvider>(GetCurrentProducerProvider); } public static void UsingEventHub<TBus>(this IRiderRegistrationConfigurator<TBus> configurator, Action<IRiderRegistrationContext, IEventHubFactoryConfigurator> configure) where TBus : class, IBus { if (configurator == null) throw new ArgumentNullException(nameof(configurator)); var factory = new EventHubRegistrationRiderFactory(configure); configurator.SetRiderFactory(factory); configurator.TryAddScoped<IEventHubRider, Bind<TBus, IEventHubProducerProvider>>((rider, provider) => Bind<TBus>.Create(GetCurrentProducerProvider(rider, provider))); } static IEventHubProducerProvider GetCurrentProducerProvider(IEventHubRider rider, IServiceProvider provider) { var contextProvider = provider.GetService<IScopedConsumeContextProvider>(); if (contextProvider != null) { return contextProvider.HasContext ? rider.GetProducerProvider(contextProvider.GetContext()) : rider.GetProducerProvider(); } return rider.GetProducerProvider(provider.GetService<ConsumeContext>()); } } }