Program.cs 1.7 KB

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