// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } var scopee = app.ApplicationServices.CreateScope(); //var context = app.ApplicationServices.GetService<MunicipalityTaxRecordContext>(); MunicipalityTaxRecordContext context = scopee.ServiceProvider.GetRequiredService <MunicipalityTaxRecordContext>(); AddTestData(context); app.UseRouting(); app.UseAuthorization(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// creating data for in-memory database. private static void AddTestData(MunicipalityTaxRecordContext context) { var MS = new MunicipalityTaxRecord { MunicipalityName = "Copenhegen", ScheduleStart = new DateTime(2016, 01, 01), ScheduleEnd = new DateTime(2016, 12, 31), TaxRate = new decimal(0.1), Period = TimePeriod.Year }; context.MunicipalityTaxRecordes.Add(MS); context.SaveChanges(); }
public MunicipalityTaxRecordRepositoryEF(MunicipalityTaxRecordContext dbContext) { this.dbContext = dbContext; }