CUB-54: implement AgentState entity, repository, and DI registration

- Add AgentState entity mapping to 'agents' table (snake_case columns)
- Add IAgentStateRepository interface (GetAllAsync, GetBySessionKeyAsync, UpdateStatusAsync)
- Add AgentStateRepository with EF Core implementation
- Add ControlCenterDbContext with ApplyConfigurationsFromAssembly
- Add AgentStateConfiguration with snake_case column mappings and indexes
- Register DbContext (Npgsql) and repository in Program.cs DI
- Add ConnectionStrings to appsettings.json
- Add EF Core 9.0.7 and Npgsql.EntityFrameworkCore.PostgreSQL 9.0.4 packages
This commit is contained in:
cubecraft-agents[bot]
2026-04-26 11:44:17 +00:00
parent 69df1562c7
commit eb08a0bc90
8 changed files with 289 additions and 0 deletions

View File

@@ -1,6 +1,9 @@
using System.Reflection;
using ControlCenter.Data;
using ControlCenter.Hubs;
using ControlCenter.Repositories;
using ControlCenter.Services;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
@@ -25,6 +28,19 @@ builder.Services.AddSwaggerGen(c =>
}
});
// ── Database ────────────────────────────────────────────────
// PostgreSQL via EF Core with Npgsql.
// Connection string from appsettings.json or environment variable.
builder.Services.AddDbContext<ControlCenterDbContext>(options =>
options.UseNpgsql(
builder.Configuration.GetConnectionString("ControlCenterDb")
?? throw new InvalidOperationException(
"Connection string 'ControlCenterDb' not found. " +
"Add it to appsettings.json or set the environment variable.")));
// ── Repositories ────────────────────────────────────────────
builder.Services.AddScoped<IAgentStateRepository, AgentStateRepository>();
// ── CORS (kiosk + remote browser) ─────────────────────────
// The Control Center frontend runs on a different origin than the backend.
// SignalR requires credentials for WebSocket transport, so we use