// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, PluginDBContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            dbContext.Database.Migrate();
            InitSeed.Initialize(dbContext);
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
        public async Task <IActionResult> RollBackMigrationAsync([FromServices] PluginDBContext dbContext, [FromServices] IServiceCollection services)
        {
            var Services = services.BuildServiceProvider();
            //full rollback
            //0 to full rollback 1 to apply where 1 also means dbContext.Database.Migrate();
            //await dbContext.Database.GetService<IMigrator>().MigrateAsync("0");

            //partial rollback
            //https://github.com/dotnet/efcore/issues/23595
            //https://github.com/dotnet/efcore/issues/9339
            // Create design-time services
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddEntityFrameworkDesignTimeServices();
            serviceCollection.AddDbContextDesignTimeServices(dbContext);
            var serviceProvider      = serviceCollection.BuildServiceProvider();
            var migrationsScaffolder = serviceProvider.GetService <IMigrationsScaffolder>();

            //var migration = migrationsScaffolder.ScaffoldMigration("20210308061104_addedTimeSlotsSql", "DBInjectionWithMultiProviders.Plugin1.Migrations.MSSQL");
            try
            {
                migrationsScaffolder.RemoveMigration(AppContext.BaseDirectory, "DBInjectionWithMultiProviders.Plugin1.Migrations.MSSQL.20210308061104_addedTimeSlotsSql", true, "");
            }
            catch (DirectoryNotFoundException)
            {
                //ignore this error as it will occur in a published project where nothing is available to write/remove on a source file
                //dispose context so we can rebuild model
                dbContext.Dispose();
                //GC.Collect();
            }
            //.RemoveMigration(AppDomain.CurrentDomain.RelativeSearchPath, "20210308061104_addedTimeSlotsSql",false,"en-US");
            return(Content("Rollback successful"));
        }
        public PluginProvider(PluginDBContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            _Context = context;
        }
        public async Task <IActionResult> ReApplyMigrationsAsync([FromServices] PluginDBContext dbContext)
        {
            // Create design-time services
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddEntityFrameworkDesignTimeServices();
            serviceCollection.AddDbContextDesignTimeServices(dbContext);
            var serviceProvider   = serviceCollection.BuildServiceProvider();
            var migrationsService = serviceProvider.GetService <IMigrator>();
            await migrationsService.MigrateAsync("20210308061104_addedTimeSlotsSql");

            dbContext.Dispose();
            //GC.Collect();
            return(Content("Migration Succesfull"));
        }