diff options
author | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-03-02 01:44:50 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadevchavali1@gmail.com> | 2019-03-02 01:44:50 +0000 |
commit | e547dfb8edf27861eeb65f7f7888610b760ecd0d (patch) | |
tree | 1644d7344f6b0c867968e33f109f0e26b607d7a2 | |
parent | 9bb48e350c79451598a2c9d195d519652c9bdc61 (diff) | |
download | newsaggregator-e547dfb8edf27861eeb65f7f7888610b760ecd0d.tar.gz newsaggregator-e547dfb8edf27861eeb65f7f7888610b760ecd0d.tar.bz2 newsaggregator-e547dfb8edf27861eeb65f7f7888610b760ecd0d.zip |
Made interface to hold aggregator job, trying to make a scoped service
-rw-r--r-- | Main/Jobs/AggregatorJob.cs | 21 |
1 files changed, 13 insertions, 8 deletions
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<Config> configs = new List<Config> { 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<DatabaseContext>(); - 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<List<Article>> parseMultiple() { |