Skip to content

Commit

Permalink
Move migrations running to Back App startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ingafen committed May 19, 2022
1 parent f4f3c44 commit c00164f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
15 changes: 13 additions & 2 deletions StarWarsKb.Back/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using StarWarsKb.Back.Model;

namespace StarWarsKb.Back
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
{
var host = CreateHostBuilder(args).Build();

using (var scope = host.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
db.Database.Migrate();
}

host.Run();
}

public static IHostBuilder CreateHostBuilder(string[] args)
Expand Down
13 changes: 1 addition & 12 deletions StarWarsKb.Back/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using StarWarsKb.Back.Model;
using StarWarsKb.Infrastructure.Model;
using StarWarsKb.Infrastructure.Services;
Expand Down Expand Up @@ -41,10 +33,7 @@ public void ConfigureServices(IServiceCollection services)
// 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();
}
if (env.IsDevelopment()) app.UseDeveloperExceptionPage();

app.UseHttpsRedirection();

Expand Down

0 comments on commit c00164f

Please sign in to comment.