55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
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();
|
|
}
|
|
/// <summary>
|
|
/// This method is for entity framework
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns></returns>
|
|
public static IWebHost BuildWebHost(string[] args)
|
|
{
|
|
return CreateWebHostBuilder(args, true);
|
|
}
|
|
public static IWebHost CreateWebHostBuilder(string[] args, bool fromEF)
|
|
{
|
|
var hostBuilder = WebHost.CreateDefaultBuilder(args)
|
|
.UseStartup<Startup>();
|
|
|
|
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<Database.OFBContext>();
|
|
db.Database.Migrate();
|
|
}
|
|
|
|
return host;
|
|
}
|
|
}
|
|
}
|