Program.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. {
  12. options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
  13. options.UseInMemoryDatabase("InMemoryDb");
  14. });
  15. builder.Services.AddTransient(typeof(IAbstractRepository<>), typeof(AbstractRepository<>));
  16. builder.Services.AddTransient<IPlayerService, PlayerService>();
  17. builder.Services.AddTransient<IPlayerRepository, PlayerRepository>();
  18. builder.Services.AddHttpClient();
  19. //builder.Services.AddSqlite<DeathwatchDbContext>("Data Source=deathwatch.db");
  20. var app = builder.Build();
  21. var scopeFactory = app.Services.GetRequiredService<IServiceScopeFactory>();
  22. using (var scope = scopeFactory.CreateScope())
  23. {
  24. //var parent = Directory.GetParent(Directory.GetCurrentDirectory()).Parent;
  25. var directory = Directory.GetCurrentDirectory();
  26. //var folderPath = Path.Combine($"{directory}", "Dotnet", "Deathwatch", "XML");
  27. var folderPath = Path.Combine($"{directory}", "XML");
  28. var db = scope.ServiceProvider.GetRequiredService<DeathwatchDbContext>();
  29. if (await db.Database.EnsureCreatedAsync())
  30. {
  31. await DbContextInitializer.Initialize(db, folderPath);
  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();