-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
48 lines (41 loc) · 2.07 KB
/
Copy pathServiceCollectionExtensions.cs
File metadata and controls
48 lines (41 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Microsoft.Extensions.DependencyInjection;
using ShellDocs.Components.Chrome;
using ShellDocs.Components.Content;
using ShellDocs.Core;
using ShellDocs.Markdown;
namespace ShellDocs.Components;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddShellDocs(this IServiceCollection services, Action<ShellDocsOptions>? configure = null)
{
var options = new ShellDocsOptions();
configure?.Invoke(options);
services.AddSingleton(options);
services.AddScoped<MobileNavState>();
services.AddScoped<ThemeState>();
services.AddScoped<SearchState>();
services.AddScoped<SidebarCollapseState>();
services.AddScoped<CodeGroupSyncState>();
services.AddScoped<DocsPageState>();
/* Auto-register the shipped content primitives so `razor:preview` blocks
in markdown can reference <Callout>, <Card>, <Steps>, <FileTree> etc.
without the consumer calling RegisterComponent<T>() themselves.
Dogfoods RegisterComponentsFromAssembly against our own Content
namespace — new primitives added under Content/ auto-appear here
without a maintainer edit to this file. Internal render machinery
(MarkdownContent, PreviewFrame) opts out via [ShellDocsIgnore]. */
options.RegisterComponentsFromAssembly<Callout>(t => t.Namespace == "ShellDocs.Components.Content");
services.AddSingleton<TypeRegistry>(_ => options.BuildTypeRegistry());
services.AddSingleton<MarkdownRenderer>(sp => new MarkdownRenderer(sp.GetRequiredService<TypeRegistry>()));
services.AddSingleton<NavigationGraph>(_ =>
{
if (!Directory.Exists(options.ContentRoot))
{
return new NavigationGraph(new NavigationNode { Url = "/", Kind = NodeKind.Section });
}
return NavigationGraphBuilder.Build(options.ContentRoot);
});
services.AddSingleton<SearchIndex>(sp => SearchIndex.FromGraph(sp.GetRequiredService<NavigationGraph>()));
return services;
}
}