Exemple #1
0
        public static async Task Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", false);

            var configuration = builder.Build();

            var dec = new DataExtractorConfiguration();

            configuration.Bind(nameof(DataExtractorConfiguration), dec);

            var serviceProvider = new ServiceCollection()
                                  .AddSingleton(dec)
                                  .AddSingleton <DataExtractor>()
                                  .AddSingleton <IBetsApiClient, BetsApiClient>(isp => new BetsApiClient(dec.BetsApiUrl))
                                  .AddDbContext <PostgreSqlDbContext>(db => db.UseNpgsql(dec.PostgreSqlConnectionString))
                                  .BuildServiceProvider();

            await serviceProvider.GetService <PostgreSqlDbContext>().Database.EnsureCreatedAsync();

            await serviceProvider.GetService <DataExtractor>().ScanPassedGamesAsync();

            Console.WriteLine("Done");
        }
 public DataExtractor(DataExtractorConfiguration configuration, PostgreSqlDbContext dbContext,
                      IBetsApiClient betsApiClient)
 {
     _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     _dbContext     = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _betsApiClient = betsApiClient ?? throw new ArgumentNullException(nameof(betsApiClient));
 }