using System.Threading.Channels; using Microsoft.EntityFrameworkCore; using Novelly.Api.Agent; using Novelly.Api.Beats; using Novelly.Api.Chapters; using Novelly.Api.Characters; using Novelly.Api.Common.Validation; using Novelly.Api.Data; using Novelly.Api.Imports; using Novelly.Api.Projects; using Novelly.Api.Questions; using Novelly.Api.Scenes; using Novelly.Api.Tags; namespace Novelly.Api.Common; /// /// Wires up every feature's services in one place. Endpoints, the embedded agent and the /// MCP server all resolve the same instances, so a capability added here is available to /// all three. /// public static class NovellyServiceRegistration { public static IServiceCollection AddNovelly(this IServiceCollection services, IConfiguration configuration) { var connectionString = configuration.GetConnectionString("Novel") ?? "Data Source=novel.db"; services.AddDbContext(options => options.UseSqlite(connectionString)); services.AddScoped(sp => sp.GetRequiredService()); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.Configure(configuration.GetSection(AgentOptions.SectionName)); services.AddScoped(); // A single unbounded queue shared by the request path (writer, in ImportService) // and the background runner (reader) — the only background-job infra in the app. services.AddSingleton(Channel.CreateUnbounded()); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddHostedService(); services.AddModelValidatorsFromAssemblyContaining(); return services; } }