public static void Initialize(IServiceProvider serviceProvider) { var serviceScope = serviceProvider.CreateScope(); using (BankingDBContext context = serviceScope.ServiceProvider.GetRequiredService <BankingDBContext>()) { try { context.Database.Migrate(); } catch (Exception ex) { } if (!context.Accounts.Any()) { context.Accounts.Add(new Account { AccountType = "Calculation", AccountBalance = 1000 }); context.Accounts.Add(new Account { AccountType = "Translation", AccountBalance = 1000 }); context.SaveChanges(); } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, BankingDBContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Banking Microservices api V1"); }); new Seed(context).SeedAsync().Wait(); app.UseMvc(); }
public AccountRepository(BankingDBContext context) { _context = context; }
public AccountRepository(BankingDBContext ctx) { _ctx = ctx; }
public AccountRepository(BankingDBContext bankingDBContext) { _bankingDBContext = bankingDBContext; }
public AccountRepository(BankingDBContext dbContext) { this._ctx = dbContext; }
public Seed(BankingDBContext bankingDBContext) { this.bankingDBContext = bankingDBContext; }