Program.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using DataLayer;
  2. using DataLayer.Interfaces;
  3. using Deathwatch.Data;
  4. using Services;
  5. using Services.Interfaces;
  6. using Microsoft.EntityFrameworkCore;
  7. using Infrastructure;
  8. using Microsoft.Extensions.DependencyInjection;
  9. var builder = WebApplication.CreateBuilder(args);
  10. // Add services to the container.
  11. builder.Services.AddRazorPages();
  12. builder.Services.AddServerSideBlazor();
  13. builder.Services.AddSingleton<WeatherForecastService>();
  14. builder.Services.AddDbContext<DeathwatchDbContext>(options =>
  15. options.UseInMemoryDatabase("InMemoryDb"));
  16. builder.Services.AddTransient(typeof(IAbstractRepository<>), typeof(AbstractRepository<>));
  17. builder.Services.AddTransient<IPlayerService, PlayerService>();
  18. builder.Services.AddTransient<IPlayerRepository, PlayerRepository>();
  19. builder.Services.AddHttpClient();
  20. //builder.Services.AddSqlite<DeathwatchDbContext>("Data Source=deathwatch.db");
  21. var currentDirectory = Directory.GetCurrentDirectory();
  22. string folderPath = $"{currentDirectory}/XML/";
  23. string outputJsonFilePath = $"{currentDirectory}/outputfile.json";
  24. var app = builder.Build();
  25. var scopeFactory = app.Services.GetRequiredService<IServiceScopeFactory>();
  26. using (var scope = scopeFactory.CreateScope())
  27. {
  28. var db = scope.ServiceProvider.GetRequiredService<DeathwatchDbContext>();
  29. if (db.Database.EnsureCreated())
  30. {
  31. DbContextInitializer.Initialize(db);
  32. }
  33. }
  34. // Configure the HTTP request pipeline.
  35. if (!app.Environment.IsDevelopment())
  36. {
  37. app.UseExceptionHandler("/Error");
  38. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  39. app.UseHsts();
  40. }
  41. app.UseHttpsRedirection();
  42. app.UseStaticFiles();
  43. app.UseRouting();
  44. app.MapBlazorHub();
  45. app.MapFallbackToPage("/_Host");
  46. app.Run();