diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index bdfa5ed9..85b6ebe0 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -71,6 +71,7 @@ namespace StardewModdingAPI.Web options.SerializerSettings.Formatting = Formatting.Indented; options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; }); + MongoDbConfig mongoConfig = this.Configuration.GetSection("MongoDB").Get(); // init background service { @@ -80,12 +81,10 @@ namespace StardewModdingAPI.Web } // init MongoDB - MongoDbConfig mongoConfig = this.Configuration.GetSection("MongoDB").Get(); - string mongoConnectionStr = mongoConfig.GetConnectionString(); - services.AddSingleton(serv => new MongoClient(mongoConnectionStr).GetDatabase(mongoConfig.Database)); - services.AddSingleton(serv => new WikiCacheRepository(serv.GetService())); + services.AddSingleton(serv => new MongoClient(mongoConfig.GetConnectionString()).GetDatabase(mongoConfig.Database)); + services.AddSingleton(serv => new WikiCacheRepository(serv.GetRequiredService())); - // init Hangfire (needs MongoDB) + // init Hangfire services .AddHangfire(config => { @@ -93,7 +92,7 @@ namespace StardewModdingAPI.Web .SetDataCompatibilityLevel(CompatibilityLevel.Version_170) .UseSimpleAssemblyNameTypeSerializer() .UseRecommendedSerializerSettings() - .UseMongoStorage(mongoConnectionStr, $"{mongoConfig.Database}-hangfire", new MongoStorageOptions + .UseMongoStorage(mongoConfig.GetConnectionString(), $"{mongoConfig.Database}-hangfire", new MongoStorageOptions { MigrationOptions = new MongoMigrationOptions(MongoMigrationStrategy.Drop) });