Program.cs 1.5 KB

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