Skip to content

Commit 4a94c20

Browse files
committed
Introduce & Implement BotEventManager
1 parent 1f5be73 commit 4a94c20

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using RealTimeWeatherMonitoringApp.Domain.Interfaces.Service;
2+
3+
namespace RealTimeWeatherMonitoringApp.Application.Interfaces.Service;
4+
5+
/// <summary>
6+
/// Responsible for attaching bots to events (e.g. publishers, notifiers)
7+
/// </summary>
8+
/// <typeparam name="TData">Data type that bots deal with</typeparam>
9+
public interface IBotEventManager<TData>
10+
{
11+
/// <summary>
12+
/// Sets up the event flow for bots by attaching them to a data change notifier and configuring them to publish their events
13+
/// through a specified publishing service. Bots will react to data changes notified by <paramref name="notifier"/> and
14+
/// their responses, if any, will be published to <paramref name="publisher"/>.
15+
/// </summary>
16+
/// <param name="notifier">Bots will subscribe to this notifier to receive updates on data changes relevant to their operations.</param>
17+
/// <param name="publisher">The publishing service through which bots can publish their events.</param>
18+
void Attach(IDataChangeNotifier<TData> notifier, IBotPublishingService publisher);
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using RealTimeWeatherMonitoringApp.Application.Interfaces;
2+
using RealTimeWeatherMonitoringApp.Application.Interfaces.Service;
3+
using RealTimeWeatherMonitoringApp.Domain.Interfaces.Service;
4+
5+
namespace RealTimeWeatherMonitoringApp.Application.Service;
6+
7+
public class BotEventManager<TData> : IBotEventManager<TData>
8+
{
9+
private readonly IBotControllerService<TData> _botControllerService;
10+
11+
public BotEventManager(IBotControllerService<TData> botControllerService) =>
12+
_botControllerService = botControllerService;
13+
14+
public void Attach(IDataChangeNotifier<TData> notifier, IBotPublishingService publisher)
15+
{
16+
var botControllers = _botControllerService.GetBotControllers(publisher);
17+
foreach (var controller in botControllers)
18+
notifier.OnDataChange += (_, args) => controller.React(args);
19+
}
20+
}

0 commit comments

Comments
 (0)