@@ -17,13 +17,10 @@ internal class OutboxMessagePublisherService<TDbContext> : BackgroundService
1717 private readonly PeriodicTimer _timer ;
1818 private readonly ILogger < OutboxMessagePublisherService < TDbContext > > _logger ;
1919 private readonly IServiceScopeFactory _serviceScopeFactory ;
20- private readonly IPublishEndpoint _publishEndpoint ;
2120
22- public OutboxMessagePublisherService ( IPublishEndpoint publishEndpoint ,
23- IServiceScopeFactory serviceScopeFactory ,
21+ public OutboxMessagePublisherService ( IServiceScopeFactory serviceScopeFactory ,
2422 ILogger < OutboxMessagePublisherService < TDbContext > > logger , Settings settings )
2523 {
26- _publishEndpoint = publishEndpoint ;
2724 _serviceScopeFactory = serviceScopeFactory ;
2825 _logger = logger ;
2926 _timer = new ( settings . PublisherTimerPeriod ) ;
@@ -38,6 +35,7 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken)
3835
3936 using var scope = _serviceScopeFactory . CreateScope ( ) ;
4037 using var dbContext = scope . ServiceProvider . GetRequiredService < TDbContext > ( ) ;
38+ var publishEndpoint = scope . ServiceProvider . GetRequiredService < IPublishEndpoint > ( ) ;
4139 using var transactionScope = await dbContext . Database . BeginTransactionAsync ( System . Data . IsolationLevel . ReadCommitted , cancellationToken ) ;
4240
4341 try
@@ -64,7 +62,7 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken)
6462
6563 var messageObject = JsonConvert . DeserializeObject ( message . Payload , type ! ) ;
6664
67- await _publishEndpoint . Publish ( messageObject ! , type ! , x => x . Headers . Set ( Constants . OutboxMessageId , message . Id ) , cancellationToken ) ;
65+ await publishEndpoint . Publish ( messageObject ! , type ! , x => x . Headers . Set ( Constants . OutboxMessageId , message . Id ) , cancellationToken ) ;
6866
6967 publishedMessageIds . Add ( message . Id ) ;
7068 }
0 commit comments