using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace OFBButte.Api { public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args, false).Run(); } /// /// This method is for entity framework /// /// /// public static IWebHost BuildWebHost(string[] args) { return CreateWebHostBuilder(args, true); } public static IWebHost CreateWebHostBuilder(string[] args, bool fromEF) { var hostBuilder = WebHost.CreateDefaultBuilder(args) .UseStartup(); if (args.Length >= 1) { hostBuilder.UseUrls($"http://localhost:{args[0]}"); } var host = hostBuilder.Build(); if (fromEF) return host; using (var scope = host.Services.CreateScope()) { var db = scope.ServiceProvider.GetService(); db.Database.Migrate(); } return host; } } }