using Microsoft.EntityFrameworkCore; using PetCompanion.Data; using PetCompanion.Repositories; using PetCompanion.Services; using System.Text.Json.Serialization; namespace PetCompanion { public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers() .AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); // Configure Entity Framework Core var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); builder.Services.AddDbContext<ApplicationDbContext>(options => { options.UseSqlite(connectionString); options.EnableSensitiveDataLogging(); }); builder.Services.AddScoped<PetClassRepository>(); builder.Services.AddScoped<PetClassService>(); builder.Services.AddScoped<SkillService>(); builder.Services.AddScoped<GameItemsRepository>(); builder.Services.AddScoped<GameItemService>(); builder.Services.AddScoped<PetRepository>(); builder.Services.AddScoped<PetService>(); builder.Services.AddScoped<PetSkillRepository>(); builder.Services.AddScoped<PetInventoryRepository>(); builder.Services.AddScoped<PetSkillService>(); builder.Services.AddScoped<PetInventoryService>(); // Add CORS policy builder.Services.AddCors(options => { options.AddPolicy("AllowAll", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); }); }); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.UseAuthorization(); // After app builder is created using (var scope = app.Services.CreateScope()) { var itemService = scope.ServiceProvider.GetRequiredService<GameItemService>(); itemService.LoadItemsFromCsv("GameItemsData.csv"); } // Use CORS policy app.UseCors("AllowAll"); app.MapControllers(); app.Run(); } } }