From e547dfb8edf27861eeb65f7f7888610b760ecd0d Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sat, 2 Mar 2019 01:44:50 +0000 Subject: Made interface to hold aggregator job, trying to make a scoped service --- Main/Jobs/AggregatorJob.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'Main') diff --git a/Main/Jobs/AggregatorJob.cs b/Main/Jobs/AggregatorJob.cs index 065a1f0..6773ea3 100644 --- a/Main/Jobs/AggregatorJob.cs +++ b/Main/Jobs/AggregatorJob.cs @@ -10,7 +10,16 @@ using Database; using Aggregator; namespace Main.Jobs { - public class AggregatorJob { + public interface IAggregatorJob { + Task Start(); + } + + public class AggregatorJob : IAggregatorJob { + private DatabaseContext Context; + public AggregatorJob(DatabaseContext context) { + Context = context; + } + private static List configs = new List { new Config { Source = "BBC", @@ -44,13 +53,9 @@ namespace Main.Jobs { "https://abcnews.go.com/abcnews/topstories" }; - public async Task Start(string config) { - var builder = new DbContextOptionsBuilder(); - builder.UseMySQL(config); - using (var context = new DatabaseContext(builder.Options)) { - var articles = await parseMultiple(); - await context.InsertArticles(articles); - } + public async Task Start() { + var articles = await parseMultiple(); + await Context.InsertArticles(articles); } private async Task> parseMultiple() { -- cgit v1.2.3-13-gbd6f