Skip to content

Commit 11d731b

Browse files
committed
Implement bot factory
1 parent 416b398 commit 11d731b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using RealTimeWeatherMonitoringApp.Domain.Models;
2+
using RealTimeWeatherMonitoringApp.Infrastructure.Configuration;
3+
using RealTimeWeatherMonitoringApp.Infrastructure.Extension;
4+
using RealTimeWeatherMonitoringApp.Infrastructure.Interfaces.Factory;
5+
6+
namespace RealTimeWeatherMonitoringApp.Infrastructure.Factory;
7+
8+
public class BotFactory<TEvaluated> : IBotFactory<TEvaluated>
9+
{
10+
private readonly IEvaluatorFactory<TEvaluated> _evaluatorFactory;
11+
public BotFactory(IEvaluatorFactory<TEvaluated> evaluatorFactory) => _evaluatorFactory = evaluatorFactory;
12+
13+
public Bot<TEvaluated> CreateBot(BotConfiguration configuration)
14+
{
15+
var evaluator = configuration.Conditions
16+
.Select(config => _evaluatorFactory.CreateEvaluator(config))
17+
.EvaluateAll();
18+
19+
return new Bot<TEvaluated>(
20+
configuration.Name,
21+
configuration.Enabled,
22+
configuration.Message,
23+
evaluator);
24+
}
25+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using RealTimeWeatherMonitoringApp.Domain.Models;
2+
using RealTimeWeatherMonitoringApp.Infrastructure.Configuration;
3+
4+
namespace RealTimeWeatherMonitoringApp.Infrastructure.Interfaces.Factory;
5+
6+
public interface IBotFactory<TEvaluated>
7+
{
8+
Bot<TEvaluated> CreateBot(BotConfiguration configuration);
9+
}

0 commit comments

Comments
 (0)