diff --git a/Program.cs b/Program.cs index 417598c..6fecc78 100644 --- a/Program.cs +++ b/Program.cs @@ -62,18 +62,64 @@ builder.Services.AddSingleton(); builder.Services.AddHealthChecks() .AddCheck("mysql", tags: new[] { "ready" }); +//var app = builder.Build(); + +//// DEBUG: Log registered handlers +//var router = app.Services.GetRequiredService(); +//var handlers = app.Services.GetServices(); +//foreach (var h in handlers) +//{ +// app.Logger.LogInformation("Registered handler: {Type} with opcodes: {OpCodes}", +// h.GetType().Name, +// string.Join(", ", h.SupportedOpCodes)); +//} var app = builder.Build(); -// DEBUG: Log registered handlers -var router = app.Services.GetRequiredService(); -var handlers = app.Services.GetServices(); +// DEBUG: Directly try to resolve each service +app.Logger.LogInformation("=== DI Debug Start ==="); + +try +{ + var serializer = app.Services.GetRequiredService(); + app.Logger.LogInformation("IMessageSerializer resolved: {Type}", serializer.GetType().Name); +} +catch (Exception ex) +{ + app.Logger.LogError(ex, "Failed to resolve IMessageSerializer"); +} + +try +{ + var matchMgr = app.Services.GetRequiredService(); + app.Logger.LogInformation("MatchManager resolved OK"); +} +catch (Exception ex) +{ + app.Logger.LogError(ex, "Failed to resolve MatchManager"); +} + +try +{ + var gameHandler = app.Services.GetRequiredService(); + app.Logger.LogInformation("GameHandler resolved OK, opcodes: {Ops}", string.Join(",", gameHandler.SupportedOpCodes)); +} +catch (Exception ex) +{ + app.Logger.LogError(ex, "Failed to resolve GameHandler"); +} + +var handlers = app.Services.GetServices().ToList(); +app.Logger.LogInformation("IClientMessageHandler count: {Count}", handlers.Count); foreach (var h in handlers) { - app.Logger.LogInformation("Registered handler: {Type} with opcodes: {OpCodes}", + app.Logger.LogInformation(" Handler: {Type} with opcodes: {OpCodes}", h.GetType().Name, string.Join(", ", h.SupportedOpCodes)); } +var router = app.Services.GetRequiredService(); +app.Logger.LogInformation("MessageRouter resolved OK"); +app.Logger.LogInformation("=== DI Debug End ==="); // ---- Health endpoints ---- app.MapGet("/health/live", () => Results.Ok(new { status = "live" }));