/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit/Configuration/DependencyInjection/DependencyInjectionTransactionExtensions.cs
61 строка
3 KB
Chris Patterson
Outbox configuration redesigned, inbox cleanup service added, query optimizations
19 июн 2022, 02:04
19 июн 2022, 02:04
936f473
Код
Авторство
О чём код?
namespace MassTransit { using DependencyInjection; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Transactions; public static class DependencyInjectionTransactionExtensions { /// <summary> /// Adds <see cref="ITransactionalBus" /> to the container with singleton lifetime, which can be used instead of <see cref="IBus" /> to enlist /// published/sent messages in the current transaction. It isn't truly transactional, but delays the messages until /// the transaction being to commit. This has a very limited purpose and is not meant for general use. /// </summary> public static void AddTransactionalEnlistmentBus(this IBusRegistrationConfigurator busConfigurator) { busConfigurator.TryAddSingleton<ITransactionalBus>(provider => new TransactionalEnlistmentBus(provider.GetService<IBus>())); busConfigurator.ReplaceScoped<IScopedBusContextProvider<IBus>, TransactionalScopedBusContextProvider<IBus>>(); } /// <summary> /// Adds <see cref="ITransactionalBus" /> to the container with singleton lifetime, which can be used instead of <see cref="IBus" /> to enlist /// published/sent messages in the current transaction. It isn't truly transactional, but delays the messages until /// the transaction being to commit. This has a very limited purpose and is not meant for general use. /// </summary> public static void AddTransactionalEnlistmentBus<TBus>(this IBusRegistrationConfigurator<TBus> busConfigurator) where TBus : class, IBus { busConfigurator.TryAddSingleton<ITransactionalBus>(provider => new TransactionalEnlistmentBus(provider.GetRequiredService<TBus>())); busConfigurator.ReplaceScoped<IScopedBusContextProvider<TBus>, TransactionalScopedBusContextProvider<TBus>>(); } /// <summary> /// Adds <see cref="ITransactionalBus" /> to the container with scoped lifetime, which can be used to release the messages to the bus /// immediately after a transaction commit. This has a very limited purpose and is not meant for general use. /// It is recommended this is scoped within a unit of work (e.g. Http Request) /// </summary> public static void AddTransactionalBus(this IBusRegistrationConfigurator busConfigurator) { busConfigurator.TryAddScoped<ITransactionalBus>(provider => new TransactionalBus(provider.GetService<IBus>())); busConfigurator.ReplaceScoped<IScopedBusContextProvider<IBus>, TransactionalScopedBusContextProvider<IBus>>(); } /// <summary> /// Adds <see cref="ITransactionalBus" /> to the container with scoped lifetime, which can be used to release the messages to the bus /// immediately after a transaction commit. This has a very limited purpose and is not meant for general use. /// It is recommended this is scoped within a unit of work (e.g. Http Request) /// </summary> public static void AddTransactionalBus<TBus>(this IBusRegistrationConfigurator<TBus> busConfigurator) where TBus : class, IBus { busConfigurator.TryAddScoped<ITransactionalBus>(provider => new TransactionalBus(provider.GetRequiredService<TBus>())); busConfigurator.ReplaceScoped<IScopedBusContextProvider<TBus>, TransactionalScopedBusContextProvider<TBus>>(); } } }