Hinzufügen des EnvelopeGenerator.Terminal-Projekts mit CLI-Unterstützung

Die Lösung wurde aktualisiert und enthält nun ein neues Projekt `EnvelopeGenerator.Terminal` für .NET 8.0. Hinzufügen der Klassen `CommandManager` und `DependencyInjection` für die Befehlsausführung und die Injektion von Abhängigkeiten mit CommandDotNet. Die Klasse `Program` wurde eingeführt, um den Anwendungshost einzurichten und Befehle auszuführen. Hinzufügen der erforderlichen Paketverweise in der Projektdatei zur Unterstützung neuer Funktionen.
This commit is contained in:
Developer 02 2025-04-01 18:58:26 +02:00
parent ea09edbc7f
commit 031f0d4cce
5 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,14 @@
using CommandDotNet;
using System.Reflection;
namespace EnvelopeGenerator.Terminal;
public class CommandManager
{
[DefaultCommand]
public void Execute([Option(Description = "print envelope generator termianal version.")] bool version)
{
if(version)
Console.WriteLine($"v{Assembly.GetExecutingAssembly().GetName().Version}");
}
}

View File

@ -0,0 +1,28 @@
using CommandDotNet.NameCasing;
using CommandDotNet;
using Microsoft.Extensions.DependencyInjection;
using CommandDotNet.IoC.MicrosoftDependencyInjection;
namespace EnvelopeGenerator.Terminal;
public static class DependencyInjection
{
public static IServiceCollection AddCommandManagerRunner(this IServiceCollection services, Case @case = Case.KebabCase)
{
return services
.AddSingleton<CommandManager>()
.AddSingleton(sp =>
{
var runner = new AppRunner<CommandManager>();
runner.UseMicrosoftDependencyInjection(sp);
runner.UseNameCasing(@case);
return runner;
});
}
public static Task<int> RunCommandManagerRunner(this IServiceProvider provider, string[] args)
{
var runner = provider.GetRequiredService<AppRunner<CommandManager>>();
return runner.RunAsync(args);
}
}

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandDotNet" Version="8.1.1" />
<PackageReference Include="CommandDotNet.IoC.MicrosoftDependencyInjection" Version="7.1.0" />
<PackageReference Include="CommandDotNet.NameCasing" Version="5.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.3" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,17 @@
using Microsoft.Extensions.Hosting;
namespace EnvelopeGenerator.Terminal;
public class Program
{
static async Task<int> Main(string[] args)
{
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddCommandManagerRunner();
var app = builder.Build();
return await app.Services.RunCommandManagerRunner(args);
}
}

View File

@ -35,6 +35,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "infrastructure", "infrastru
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "presentation", "presentation", "{E3C758DC-914D-4B7E-8457-0813F1FDB0CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EnvelopeGenerator.Terminal", "EnvelopeGenerator.Terminal\EnvelopeGenerator.Terminal.csproj", "{A9F9B431-BB9B-49B8-9E2C-0703634A653A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -85,6 +87,10 @@ Global
{A4D0DD1A-67BC-4E1A-AD29-BC4BC0D41399}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4D0DD1A-67BC-4E1A-AD29-BC4BC0D41399}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4D0DD1A-67BC-4E1A-AD29-BC4BC0D41399}.Release|Any CPU.Build.0 = Release|Any CPU
{A9F9B431-BB9B-49B8-9E2C-0703634A653A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A9F9B431-BB9B-49B8-9E2C-0703634A653A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9F9B431-BB9B-49B8-9E2C-0703634A653A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9F9B431-BB9B-49B8-9E2C-0703634A653A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -104,6 +110,7 @@ Global
{A4D0DD1A-67BC-4E1A-AD29-BC4BC0D41399} = {0CBC2432-A561-4440-89BC-671B66A24146}
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {134D4164-B291-4E19-99B9-E4FA3AFAB62C}
{E3C758DC-914D-4B7E-8457-0813F1FDB0CB} = {134D4164-B291-4E19-99B9-E4FA3AFAB62C}
{A9F9B431-BB9B-49B8-9E2C-0703634A653A} = {E3C758DC-914D-4B7E-8457-0813F1FDB0CB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {73E60370-756D-45AD-A19A-C40A02DACCC7}