Created
May 8, 2025 07:59
-
-
Save ramonsmits/0ccb62a2f67491d00638ee206048b28a to your computer and use it in GitHub Desktop.
NServiceBus - Unsubscribe from events during startup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.Extensions.Hosting; | |
class UnsubscribeHostedService(IMessageSession messageSession : BackgroundService | |
{ | |
protected override async Task ExecuteAsync(CancellationToken stoppingToken) | |
{ | |
await messageSession.Unsubscribe<MyEvent>(); | |
} | |
} | |
// var host = Host.CreateDefaultBuilder(args) | |
// .ConfigureServices(services => { | |
// services.AddHostedService<UnsubscribeHostedService>(); | |
// }) | |
// .Build(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment