I have an ASP NET app that uses MongoDb. Each time app starts I want to check that certain collections are created and have some initial data in them. What would be the best way to do this?
In ConfigureServices I have:
IConfigurationSection dbSettingsSection = Configuration.GetSection(nameof(DbSettings));
services.Configure<DbSettings>(dbSettingsSection);
services.AddSingleton<IDbSettings>(c => c.GetRequiredService<IOptions<DbSettings>>().Value);
MongoModelBuilder builder = new(dbSettingsSection.Get<DbSettings>());
And the builder instance would have the necessary logic. Is this a correct approach?