Skip to content

Commit 5ab4360

Browse files
committed
Refactor BotApp to manage its own CancellationTokenSource
The constructor of the `BotApp` class in the `TelegramBot` namespace has been modified to remove the `cancellationTokenSource` parameter. Instead, a new `CancellationTokenSource` instance is created within the constructor. In the `BotBuilder` class within the `TelegramBot.Builders` namespace, the instantiation of `CancellationTokenSource` has been removed, and the `BotApp` constructor is called without passing a `cancellationTokenSource` parameter. These changes simplify the instantiation process of `BotApp` by encapsulating the creation of `CancellationTokenSource` within the class itself.
1 parent 01f8c93 commit 5ab4360

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

Sources/TelegramBot/BotApp.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@ public class BotApp : IBot
4141
/// </summary>
4242
/// <param name="client">Telegram bot client.</param>
4343
/// <param name="serviceProvider">Service provider.</param>
44-
/// <param name="cancellationTokenSource">Cancellation token source.</param>
45-
public BotApp(TelegramBotClient client, ServiceProvider serviceProvider, CancellationTokenSource cancellationTokenSource)
44+
public BotApp(TelegramBotClient client, ServiceProvider serviceProvider)
4645
{
4746
_client = client;
4847
_serviceProvider = serviceProvider;
4948
_controllerMethods = new List<MethodInfo>();
50-
_cancellationTokenSource = cancellationTokenSource;
49+
_cancellationTokenSource = new CancellationTokenSource();
5150
_logger = serviceProvider.GetRequiredService<ILogger<BotApp>>();
5251
}
5352

Sources/TelegramBot/Builders/BotBuilder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,8 @@ public IBot Build()
140140
{
141141
Services.AddSingleton<IKeyValueProvider, InMemoryKeyValueProvider>();
142142
}
143-
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
144143
Services.AddSingleton<IHostApplicationLifetime, HostApplicationLifetime>(x => new HostApplicationLifetime());
145-
return new BotApp(client, Services.BuildServiceProvider(), cancellationTokenSource);
144+
return new BotApp(client, Services.BuildServiceProvider());
146145
}
147146
}
148147
}

0 commit comments

Comments
 (0)