-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathProgram.cs
64 lines (53 loc) · 2.99 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Interactive_CC_bot.Workers;
using Inverse_CC_bot.DataAccess.Repositories;
using Inverse_CC_bot.Interfaces;
using Inverse_CC_bot.Services;
using Inverse_CC_bot.Types;
using Inverse_CC_bot.Workers;
using Microsoft.Extensions.Options;
// Enable Dapper snake_case to PascalCase mapping
Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.SetBasePath(AppContext.BaseDirectory);
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
})
.ConfigureServices((hostContext, services) =>
{
// Register AppConfig as a singleton, bound from appsettings.json
services.Configure<AppConfig>(hostContext.Configuration.GetSection("AppConfig"));
services.AddSingleton(sp => sp.GetRequiredService<IOptions<AppConfig>>().Value);
// Register other services
services.AddScoped<IRedditScrapingService, RedditScrapingService>();
string connectionString = hostContext.Configuration.GetConnectionString("Database");
string apiKey = hostContext.Configuration.GetSection("ApiConfig:ApiKey").Value;
string apiSecret = hostContext.Configuration.GetSection("ApiConfig:ApiSecret").Value;
services.AddScoped<IExchangeService>(_ => new ExchangeService(Inverse_CC_bot.Enums.ExchangeNameEnum.Binance, apiKey, apiSecret));
// Register the DALs with the connection string
services.AddScoped<IRedditDAL>(sp => new RedditDAL(connectionString));
services.AddScoped<ICoinsDAL>(sp => new CoinsDAL(connectionString));
services.AddScoped<ICoinSentimentsDAL>(sp => new CoinSentimentsDAL(connectionString));
services.AddScoped<ISentimentAnalysisService, SentimentAnalysisService>();
services.AddScoped<ISentimentAggregatorService, SentimentAggregatorService>();
services.AddScoped<IOrdersDAL>(sp => new OrdersDAL(connectionString));
services.AddScoped<IPortfolioDAL>(sp => new PortfolioDAL(connectionString));
services.AddScoped<IStatisticsDAL>(sp => new StatisticsDAL(connectionString));
// Register other services as needed
services.AddScoped<ISentimentAnalysisService, SentimentAnalysisService>();
services.AddScoped<ISentimentAggregatorService, SentimentAggregatorService>();
// Register RedditPostsWorker and other workers
services.AddHostedService<RedditPostsWorker>();
services.AddHostedService<SentimentLabellerWorker>();
services.AddHostedService<SentimentAggregatorWorker>();
services.AddHostedService<StatisticsWorker>();
services.AddHostedService(provider =>
{
var logger = provider.GetRequiredService<ILogger<ExchangeBuyWorker>>();
var serviceProvider = provider.GetRequiredService<IServiceProvider>();
var appConfig = provider.GetRequiredService<AppConfig>();
return new ExchangeBuyWorker(logger, serviceProvider, appConfig);
});
})
.Build();
host.Run();