Skip to content

Commit d57dbd7

Browse files
committed
Introduce & Implement BotControllerService
1 parent 5855453 commit d57dbd7

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace RealTimeWeatherMonitoringApp.Domain.Interfaces.Service;
2+
3+
public interface IBotControllerService<TEvaluated>
4+
{
5+
IEnumerable<IBotController<TEvaluated>> GetBotControllers();
6+
7+
/// <summary>
8+
/// Attaches the bot controllers to the given publishing service before fetching them.
9+
/// </summary>
10+
/// <param name="publishingService">A publishing service that will receive all bot controllers events</param>
11+
/// <returns>A collection of bot controllers attached to the given publishing service</returns>
12+
IEnumerable<IBotController<TEvaluated>> GetBotControllers(IBotPublishingService publishingService);
13+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using RealTimeWeatherMonitoringApp.Domain.Interfaces;
2+
using RealTimeWeatherMonitoringApp.Domain.Interfaces.Repository;
3+
using RealTimeWeatherMonitoringApp.Domain.Interfaces.Service;
4+
using RealTimeWeatherMonitoringApp.Domain.Models.Controller;
5+
6+
namespace RealTimeWeatherMonitoringApp.Domain.Service;
7+
8+
public class BotControllerService<TEvaluated> : IBotControllerService<TEvaluated>
9+
{
10+
private readonly Lazy<IEnumerable<BotController<TEvaluated>>> _botControllers;
11+
12+
public BotControllerService(IBotRepository<TEvaluated> repository)
13+
{
14+
_botControllers = new Lazy<IEnumerable<BotController<TEvaluated>>>(() =>
15+
repository.GetAll().Select(b => new BotController<TEvaluated>(b)));
16+
}
17+
18+
public IEnumerable<IBotController<TEvaluated>> GetBotControllers() => _botControllers.Value;
19+
20+
public IEnumerable<IBotController<TEvaluated>> GetBotControllers(IBotPublishingService publishingService)
21+
{
22+
return _botControllers.Value.Select(botController =>
23+
new PublisherBotController<TEvaluated>(botController, publishingService));
24+
}
25+
}

0 commit comments

Comments
 (0)