ScientificReport
Program.cs
Go to the documentation of this file.
1 using System;
2 using Microsoft.AspNetCore;
3 using Microsoft.AspNetCore.Hosting;
4 using Microsoft.EntityFrameworkCore;
5 using Microsoft.Extensions.DependencyInjection;
6 using Microsoft.Extensions.Logging;
9 
10 namespace ScientificReport
11 {
12  // ReSharper disable once ClassNeverInstantiated.Global
13  public class Program
14  {
15  public static void Main(string[] args)
16  {
17  var host = CreateWebHostBuilder(args).Build();
18 
19  // just for automated migration and seeding on startup
20  using (var scope = host.Services.CreateScope())
21  {
22  var serviceProvider = scope.ServiceProvider;
23 
24  try
25  {
26  var context = serviceProvider.GetRequiredService<ScientificReportDbContext>();
27  context.Database.Migrate();
28  SeedData.Initialize(serviceProvider, context);
29  }
30  catch (Exception ex)
31  {
32  var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
33  logger.LogError(ex, "An error occurred seeding the DB.");
34  }
35  }
36 
37  host.Run();
38  }
39 
40  private static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
41  WebHost.CreateDefaultBuilder(args)
42  .ConfigureLogging((context, logging) => {
43  var config = context.Configuration.GetSection("Logging");
44  logging.AddConfiguration(config);
45  logging.AddConsole();
46  logging.AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Warning);
47  logging.AddFilter("Microsoft.AspNetCore.HttpsPolicy", LogLevel.Error);
48  logging.AddFilter("Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager", LogLevel.Warning);
49  logging.AddFilter("Microsoft.AspNetCore.Hosting.Internal.WebHost", LogLevel.Warning);
50  logging.AddFilter("Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware", LogLevel.Warning);
51 // logging.AddFilter("Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker", LogLevel.Warning);
52  logging.AddFilter("Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor", LogLevel.Warning);
53  logging.AddFilter("Microsoft.AspNetCore.Mvc.Formatters", LogLevel.Warning);
54  })
55  .UseStartup<Startup>();
56  }
57 }
static void Initialize(IServiceProvider serviceProvider, ScientificReportDbContext context)
Initializes the basic data, the entrypoint for all seeds
Definition: SeedData.cs:37
static void Main(string[] args)
Definition: Program.cs:15
This class is created to seed the basic data to be used in both frontend and backend and it is for de...
Definition: SeedData.cs:32