-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationRunner.cs
More file actions
32 lines (27 loc) · 1.23 KB
/
ApplicationRunner.cs
File metadata and controls
32 lines (27 loc) · 1.23 KB
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
using DevSubmarine.DiscordBot.Tools.DatabaseBootstrapper.CollectionCreators;
namespace DevSubmarine.DiscordBot.Tools.DatabaseBootstrapper
{
public class ApplicationRunner
{
private readonly MongoClient _client;
private readonly MongoOptions _options;
private readonly ILogger _log;
private readonly IEnumerable<ICollectionCreator> _collectionCreators;
public ApplicationRunner(IOptions<MongoOptions> options, ILogger<ApplicationRunner> log, IMongoDatabaseClient client,
IEnumerable<ICollectionCreator> collectionCreators)
{
this._options = options.Value;
this._log = log;
this._client = client.Client;
this._collectionCreators = collectionCreators;
}
public async Task RunAsync()
{
this._log.LogInformation("Connecting to the database {Database}", this._options.DatabaseName);
IMongoDatabase db = this._client.GetDatabase(this._options.DatabaseName);
foreach (ICollectionCreator collectionCreator in this._collectionCreators)
await collectionCreator.ProcessCollectionAsync().ConfigureAwait(false);
this._log.LogInformation("Done");
}
}
}