diff --git a/Doki.sln b/Doki.sln index 7958782..04e8537 100644 --- a/Doki.sln +++ b/Doki.sln @@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Output", "Output", "{568576 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doki.Output.ClassLibrary", "src\Doki.Output.ClassLibrary\Doki.Output.ClassLibrary.csproj", "{9619825A-9DD5-4D82-9BBA-6747A8313275}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doki.Output.Extensions", "src\Doki.Output.Extensions\Doki.Output.Extensions.csproj", "{A89D22B2-2427-4863-A2D9-9E1BEFF37C61}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -40,6 +42,7 @@ Global {57EF4554-C84D-4988-94CF-9D6E908BE10C} = {568576F3-3D48-459E-B4D2-1790DAE80E7A} {33DFFEBE-DB9E-4960-BB4E-3B58399E132C} = {568576F3-3D48-459E-B4D2-1790DAE80E7A} {9619825A-9DD5-4D82-9BBA-6747A8313275} = {568576F3-3D48-459E-B4D2-1790DAE80E7A} + {A89D22B2-2427-4863-A2D9-9E1BEFF37C61} = {568576F3-3D48-459E-B4D2-1790DAE80E7A} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6F31B87A-2BD3-4FB4-8C08-7E059A338D4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -82,5 +85,9 @@ Global {9619825A-9DD5-4D82-9BBA-6747A8313275}.Debug|Any CPU.Build.0 = Debug|Any CPU {9619825A-9DD5-4D82-9BBA-6747A8313275}.Release|Any CPU.ActiveCfg = Release|Any CPU {9619825A-9DD5-4D82-9BBA-6747A8313275}.Release|Any CPU.Build.0 = Release|Any CPU + {A89D22B2-2427-4863-A2D9-9E1BEFF37C61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A89D22B2-2427-4863-A2D9-9E1BEFF37C61}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A89D22B2-2427-4863-A2D9-9E1BEFF37C61}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A89D22B2-2427-4863-A2D9-9E1BEFF37C61}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/src/Doki.CommandLine/Commands/GenerateCommand.cs b/src/Doki.CommandLine/Commands/GenerateCommand.cs index 5982f4c..526df00 100644 --- a/src/Doki.CommandLine/Commands/GenerateCommand.cs +++ b/src/Doki.CommandLine/Commands/GenerateCommand.cs @@ -5,6 +5,7 @@ using System.Text.Json; using System.Xml.XPath; using Doki.Output; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileSystemGlobbing; using Microsoft.Extensions.FileSystemGlobbing.Abstractions; using Microsoft.Extensions.Logging; @@ -92,7 +93,16 @@ private async Task HandleCommandAsync(InvocationContext context) return -1; } - var generator = new DocumentationGenerator(); + var serviceCollection = new ServiceCollection(); + serviceCollection.AddSingleton(_logger); + serviceCollection.AddSingleton(provider => + new DocumentationGenerator(provider.GetRequiredService())); + + //TODO load outputs + + var serviceProvider = serviceCollection.BuildServiceProvider(); + + var generator = serviceProvider.GetRequiredService(); var configureResult = await ConfigureDocumentationGeneratorAsync(new GenerateContext { @@ -214,7 +224,7 @@ private async Task LoadOutputsAsync(GenerateContext context, CancellationTo } //TODO refactor output loading - + var outputType = await LoadOutputAsync(context.Directory, output, context.AllowPreview, cancellationToken); if (outputType == null) @@ -226,8 +236,6 @@ private async Task LoadOutputsAsync(GenerateContext context, CancellationTo _logger.LogDebug("Adding output: {OutputType}", outputType); var outputAttribute = outputType.GetCustomAttribute(); - - } return 0; diff --git a/src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs b/src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs index d3c117f..fe2c889 100644 --- a/src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs +++ b/src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs @@ -1,6 +1,6 @@ namespace Doki.Output.ClassLibrary; -public sealed class ClassLibraryOutput(IOutputOptions options) : IOutput +internal class ClassLibraryOutput(IOutputOptions options) : IOutput { public async Task WriteAsync(ContentList contentList, CancellationToken cancellationToken = default) { diff --git a/src/Doki.Output.ClassLibrary/ClassLibraryOutputExtensions.cs b/src/Doki.Output.ClassLibrary/ClassLibraryOutputExtensions.cs new file mode 100644 index 0000000..dd3c840 --- /dev/null +++ b/src/Doki.Output.ClassLibrary/ClassLibraryOutputExtensions.cs @@ -0,0 +1,19 @@ +using Doki.Output.Extensions; +using Microsoft.Extensions.DependencyInjection; + +namespace Doki.Output.ClassLibrary; + +public static class ClassLibraryOutputExtensions +{ + [DokiOutputRegistration] + public static IServiceCollection AddClassLibraryOutput(this IServiceCollection services) + { + ArgumentNullException.ThrowIfNull(services); + + //TODO add options + + services.AddSingleton(); + + return services; + } +} \ No newline at end of file diff --git a/src/Doki.Output.ClassLibrary/Doki.Output.ClassLibrary.csproj b/src/Doki.Output.ClassLibrary/Doki.Output.ClassLibrary.csproj index aeb7cd6..129f873 100644 --- a/src/Doki.Output.ClassLibrary/Doki.Output.ClassLibrary.csproj +++ b/src/Doki.Output.ClassLibrary/Doki.Output.ClassLibrary.csproj @@ -20,6 +20,7 @@ + diff --git a/src/Doki.Output.Extensions/Doki.Output.Extensions.csproj b/src/Doki.Output.Extensions/Doki.Output.Extensions.csproj new file mode 100644 index 0000000..1a021e5 --- /dev/null +++ b/src/Doki.Output.Extensions/Doki.Output.Extensions.csproj @@ -0,0 +1,25 @@ + + + + Doki.Output.Extensions + david@vollmers.org + David Vollmers + Doki Output Extensions + https://github.com/DavidVollmers/doki + MIT + README.md + logo-64x64.png + git + https://github.com/DavidVollmers/doki.git + net6.0;net7.0;net8.0 + 12 + enable + enable + ..\..\nuget + + + + + + + diff --git a/src/Doki.Output.Extensions/DokiOutputRegistrationAttribute.cs b/src/Doki.Output.Extensions/DokiOutputRegistrationAttribute.cs new file mode 100644 index 0000000..1e9893d --- /dev/null +++ b/src/Doki.Output.Extensions/DokiOutputRegistrationAttribute.cs @@ -0,0 +1,6 @@ +namespace Doki.Output.Extensions; + +[AttributeUsage(AttributeTargets.Method)] +public sealed class DokiOutputRegistrationAttribute : Attribute +{ +} \ No newline at end of file diff --git a/src/Doki.Output.Markdown/Doki.Output.Markdown.csproj b/src/Doki.Output.Markdown/Doki.Output.Markdown.csproj index 4f47224..677e89b 100644 --- a/src/Doki.Output.Markdown/Doki.Output.Markdown.csproj +++ b/src/Doki.Output.Markdown/Doki.Output.Markdown.csproj @@ -20,6 +20,7 @@ + diff --git a/src/Doki.Output.Markdown/MarkdownOutput.cs b/src/Doki.Output.Markdown/MarkdownOutput.cs index 3743501..7c1d37d 100644 --- a/src/Doki.Output.Markdown/MarkdownOutput.cs +++ b/src/Doki.Output.Markdown/MarkdownOutput.cs @@ -3,7 +3,7 @@ namespace Doki.Output.Markdown; -public sealed class MarkdownOutput(IOutputOptions options) : IOutput +internal class MarkdownOutput(IOutputOptions options) : IOutput { public async Task WriteAsync(ContentList contentList, CancellationToken cancellationToken = default) { diff --git a/src/Doki.Output.Markdown/MarkdownOutputExtensions.cs b/src/Doki.Output.Markdown/MarkdownOutputExtensions.cs new file mode 100644 index 0000000..d997bb7 --- /dev/null +++ b/src/Doki.Output.Markdown/MarkdownOutputExtensions.cs @@ -0,0 +1,19 @@ +using Doki.Output.Extensions; +using Microsoft.Extensions.DependencyInjection; + +namespace Doki.Output.Markdown; + +public static class MarkdownOutputExtensions +{ + [DokiOutputRegistration] + public static IServiceCollection AddMarkdownOutput(this IServiceCollection services) + { + ArgumentNullException.ThrowIfNull(services); + + //TODO add options + + services.AddSingleton(); + + return services; + } +} \ No newline at end of file diff --git a/src/Doki/Doki.csproj b/src/Doki/Doki.csproj index cc93fb7..0eb2728 100644 --- a/src/Doki/Doki.csproj +++ b/src/Doki/Doki.csproj @@ -23,7 +23,7 @@ - +