| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using DataLayer;
- using DataLayer.Interfaces;
- using Microsoft.EntityFrameworkCore;
- using Services;
- using Services.Interfaces;
- var builder = WebApplication.CreateBuilder(args);
- // Add services to the container.
- builder.Services.AddRazorPages();
- builder.Services.AddServerSideBlazor();
- builder.Services.AddDbContext<DeathwatchDbContext>(options =>
- {
- options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
- options.UseInMemoryDatabase("InMemoryDb");
- });
- builder.Services.AddTransient(typeof(IAbstractRepository<>), typeof(AbstractRepository<>));
- builder.Services.AddTransient<IPlayerService, PlayerService>();
- builder.Services.AddTransient<IPlayerRepository, PlayerRepository>();
- builder.Services.AddHttpClient();
- //builder.Services.AddSqlite<DeathwatchDbContext>("Data Source=deathwatch.db");
- var app = builder.Build();
- var scopeFactory = app.Services.GetRequiredService<IServiceScopeFactory>();
- using (var scope = scopeFactory.CreateScope())
- {
- //var parent = Directory.GetParent(Directory.GetCurrentDirectory()).Parent;
- var directory = Directory.GetCurrentDirectory();
- //var folderPath = Path.Combine($"{directory}", "Dotnet", "Deathwatch", "XML");
- var folderPath = Path.Combine($"{directory}", "XML");
- var db = scope.ServiceProvider.GetRequiredService<DeathwatchDbContext>();
- if (await db.Database.EnsureCreatedAsync())
- {
- await DbContextInitializer.Initialize(db, folderPath);
- }
- }
- // Configure the HTTP request pipeline.
- //if (!app.Environment.IsDevelopment())
- //{
- app.UseExceptionHandler("/Error");
- // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
- app.UseHsts();
- //}
- app.UseHttpsRedirection();
- app.UseStaticFiles();
- app.UseRouting();
- app.MapBlazorHub();
- app.MapFallbackToPage("/_Host");
- app.Run();
|