Files
novelly/src/Novelly.Api/Common/NovellyServiceRegistration.cs
T
James Wampler 189ebf3237 Add outline import feature; drop Dto naming, map entities at the API boundary
Services now return entities; endpoints (and the agent toolsets) map to
*Response records instead of services building wire DTOs themselves.
Also brings in the outline-import agent, MCP tool, ledger and web dialog
that were already in progress on disk.
2026-08-06 18:36:40 -07:00

59 lines
2.2 KiB
C#

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;
/// <summary>
/// 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.
/// </summary>
public static class NovellyServiceRegistration
{
public static IServiceCollection AddNovelly(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString("Novel")
?? "Data Source=novel.db";
services.AddDbContext<NovelDbContext>(options => options.UseSqlite(connectionString));
services.AddScoped<INovelDbContext>(sp => sp.GetRequiredService<NovelDbContext>());
services.AddScoped<ProjectService>();
services.AddScoped<CharacterService>();
services.AddScoped<CharacterArcService>();
services.AddScoped<BeatService>();
services.AddScoped<TagService>();
services.AddScoped<ChapterService>();
services.AddScoped<SceneService>();
services.AddScoped<OpenQuestionService>();
services.AddScoped<NovelAgentToolset>();
services.AddScoped<NovelAgentService>();
services.Configure<AgentOptions>(configuration.GetSection(AgentOptions.SectionName));
services.AddScoped<IAgentModelClient, AnthropicAgentModelClient>();
// 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<Guid>());
services.AddScoped<ImportService>();
services.AddScoped<ImportAgentToolset>();
services.AddScoped<ImportAgentService>();
services.AddHostedService<ImportJobRunner>();
services.AddModelValidatorsFromAssemblyContaining<Program>();
return services;
}
}