|
1 | 1 | using Microsoft.Extensions.DependencyInjection; |
| 2 | +using ShellDocs.Components.Chrome; |
2 | 3 | using ShellDocs.Core; |
| 4 | +using ShellDocs.Markdown; |
3 | 5 |
|
4 | 6 | namespace ShellDocs.Components; |
5 | 7 |
|
6 | | -/// Registers ShellDocs services with the consumer's DI container. |
7 | | -/// Consumer's Program.cs calls this once — everything else is discovered by convention. |
8 | 8 | public static class ServiceCollectionExtensions |
9 | 9 | { |
10 | | - public static IServiceCollection AddShellDocs( |
11 | | - this IServiceCollection services, |
12 | | - Action<ShellDocsOptions>? configure = null) |
| 10 | + public static IServiceCollection AddShellDocs(this IServiceCollection services, Action<ShellDocsOptions>? configure = null) |
13 | 11 | { |
14 | 12 | var options = new ShellDocsOptions(); |
15 | 13 | configure?.Invoke(options); |
16 | 14 | services.AddSingleton(options); |
17 | 15 |
|
18 | | - // Real service wiring lands in feat/core-navigation-graph + feat/markdown-pipeline. |
19 | | - // Scaffolding: keep the surface consumers will call, no implementation yet. |
20 | | - return services; |
21 | | - } |
22 | | -} |
| 16 | + services.AddScoped<MobileNavState>(); |
| 17 | + services.AddSingleton<TypeRegistry>(_ => options.BuildTypeRegistry()); |
| 18 | + services.AddSingleton<MarkdownRenderer>(sp => new MarkdownRenderer(sp.GetRequiredService<TypeRegistry>())); |
23 | 19 |
|
24 | | -/// Fluent options bag consumers configure in Program.cs. |
25 | | -public class ShellDocsOptions |
26 | | -{ |
27 | | - public string ContentRoot { get; set; } = "content"; |
28 | | - public string SiteName { get; set; } = ""; |
29 | | - public string? GitHubRepo { get; set; } |
30 | | - public bool EnableSearch { get; set; } = true; |
31 | | - public string SearchIndexPath { get; set; } = "search-index.json"; |
32 | | - public List<Type> RegisteredComponents { get; } = new(); |
| 20 | + services.AddSingleton<NavigationGraph>(_ => |
| 21 | + { |
| 22 | + if (!Directory.Exists(options.ContentRoot)) |
| 23 | + { |
| 24 | + return new NavigationGraph(new NavigationNode { Url = "/", Kind = NodeKind.Section }); |
| 25 | + } |
| 26 | + return NavigationGraphBuilder.Build(options.ContentRoot); |
| 27 | + }); |
33 | 28 |
|
34 | | - public ShellDocsOptions RegisterComponent<T>() where T : Microsoft.AspNetCore.Components.ComponentBase |
35 | | - { |
36 | | - RegisteredComponents.Add(typeof(T)); |
37 | | - return this; |
| 29 | + return services; |
38 | 30 | } |
39 | 31 | } |
0 commit comments