From 92c0bee83bd9b265a4dd4b147d13ff1e4cfe4da8 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Sun, 9 Feb 2025 15:54:48 -0600 Subject: [PATCH] feat: begin working on console app --- .../AltGen.Console.Tests.csproj | 25 +++++++++++++++++ src/AltGen.Console.Tests/UnitTest1.cs | 10 +++++++ src/AltGen.Console/AltGen.Console.csproj | 16 +++++++++++ src/AltGen.Console/Common/TypeRegistrar.cs | 28 +++++++++++++++++++ src/AltGen.Console/Common/TypeResolver.cs | 24 ++++++++++++++++ src/AltGen.Console/Program.cs | 14 ++++++++++ src/AltGen.Console/Usings.cs | 4 +++ src/AltGen.sln | 12 ++++++++ 8 files changed, 133 insertions(+) create mode 100644 src/AltGen.Console.Tests/AltGen.Console.Tests.csproj create mode 100644 src/AltGen.Console.Tests/UnitTest1.cs create mode 100644 src/AltGen.Console/AltGen.Console.csproj create mode 100644 src/AltGen.Console/Common/TypeRegistrar.cs create mode 100644 src/AltGen.Console/Common/TypeResolver.cs create mode 100644 src/AltGen.Console/Program.cs create mode 100644 src/AltGen.Console/Usings.cs diff --git a/src/AltGen.Console.Tests/AltGen.Console.Tests.csproj b/src/AltGen.Console.Tests/AltGen.Console.Tests.csproj new file mode 100644 index 0000000..ffec1a6 --- /dev/null +++ b/src/AltGen.Console.Tests/AltGen.Console.Tests.csproj @@ -0,0 +1,25 @@ + + + + net9.0 + enable + enable + false + + + + + + + + + + + + + + + + + + diff --git a/src/AltGen.Console.Tests/UnitTest1.cs b/src/AltGen.Console.Tests/UnitTest1.cs new file mode 100644 index 0000000..39b4247 --- /dev/null +++ b/src/AltGen.Console.Tests/UnitTest1.cs @@ -0,0 +1,10 @@ +namespace AltGen.Console.Tests; + +public class UnitTest1 +{ + [Fact] + public void Test1() + { + + } +} diff --git a/src/AltGen.Console/AltGen.Console.csproj b/src/AltGen.Console/AltGen.Console.csproj new file mode 100644 index 0000000..b8472d7 --- /dev/null +++ b/src/AltGen.Console/AltGen.Console.csproj @@ -0,0 +1,16 @@ + + + + Exe + net9.0 + enable + enable + + + + + + + + + diff --git a/src/AltGen.Console/Common/TypeRegistrar.cs b/src/AltGen.Console/Common/TypeRegistrar.cs new file mode 100644 index 0000000..010dbd7 --- /dev/null +++ b/src/AltGen.Console/Common/TypeRegistrar.cs @@ -0,0 +1,28 @@ +namespace AltGen.Console.Common; + +sealed class TypeRegistrar(IHostBuilder builder) : ITypeRegistrar +{ + readonly IHostBuilder _builder = builder; + + public ITypeResolver Build() + { + return new TypeResolver(_builder.Build()); + } + + public void Register(Type service, Type implementation) + { + _builder.ConfigureServices((_, services) => services.AddSingleton(service, implementation)); + } + + public void RegisterInstance(Type service, object implementation) + { + _builder.ConfigureServices((_, services) => services.AddSingleton(service, implementation)); + } + + public void RegisterLazy(Type service, Func func) + { + ArgumentNullException.ThrowIfNull(func); + + _builder.ConfigureServices((_, services) => services.AddSingleton(service, _ => func())); + } +} \ No newline at end of file diff --git a/src/AltGen.Console/Common/TypeResolver.cs b/src/AltGen.Console/Common/TypeResolver.cs new file mode 100644 index 0000000..61494de --- /dev/null +++ b/src/AltGen.Console/Common/TypeResolver.cs @@ -0,0 +1,24 @@ +namespace AltGen.Console.Common; + +sealed class TypeResolver(IHost host) : ITypeResolver, IDisposable +{ + readonly IHost _host = host ?? throw new ArgumentNullException(nameof(host)); + + public object? Resolve(Type? type) + { + if (type is null) + { + return null; + } + + return _host.Services.GetService(type); + } + + public void Dispose() + { + if (_host is IDisposable disposable) + { + disposable.Dispose(); + } + } +} \ No newline at end of file diff --git a/src/AltGen.Console/Program.cs b/src/AltGen.Console/Program.cs new file mode 100644 index 0000000..7b33f13 --- /dev/null +++ b/src/AltGen.Console/Program.cs @@ -0,0 +1,14 @@ +// TODO: We want to be able +// to provide a path to an image +// read the image +// and then post the image to our API +// get the response and display the alt text + +using Microsoft.Extensions.Hosting; + +await Host.CreateDefaultBuilder(args) + .ConfigureServices(static (_, services) => { }) + .Build() // TODO: Need special extension for integrating host with Spectre.Console + .RunAsync(); + +Console.WriteLine("Hello, World!"); \ No newline at end of file diff --git a/src/AltGen.Console/Usings.cs b/src/AltGen.Console/Usings.cs new file mode 100644 index 0000000..fdd2bfc --- /dev/null +++ b/src/AltGen.Console/Usings.cs @@ -0,0 +1,4 @@ +global using Microsoft.Extensions.DependencyInjection; +global using Microsoft.Extensions.Hosting; + +global using Spectre.Console.Cli; diff --git a/src/AltGen.sln b/src/AltGen.sln index d9e7d5d..36f70b1 100644 --- a/src/AltGen.sln +++ b/src/AltGen.sln @@ -7,6 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AltGen.API", "AltGen.API\Al EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AltGen.API.Tests", "AltGen.API.Tests\AltGen.API.Tests.csproj", "{FC95942B-3579-4F83-A447-A96D8EEF8E45}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AltGen.Console", "AltGen.Console\AltGen.Console.csproj", "{83DA683F-A2C5-4AB7-A6FD-294DFBC08D87}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AltGen.Console.Tests", "AltGen.Console.Tests\AltGen.Console.Tests.csproj", "{F7DC6A70-907B-448A-A69D-4E2E80FA3FD3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,5 +28,13 @@ Global {FC95942B-3579-4F83-A447-A96D8EEF8E45}.Debug|Any CPU.Build.0 = Debug|Any CPU {FC95942B-3579-4F83-A447-A96D8EEF8E45}.Release|Any CPU.ActiveCfg = Release|Any CPU {FC95942B-3579-4F83-A447-A96D8EEF8E45}.Release|Any CPU.Build.0 = Release|Any CPU + {83DA683F-A2C5-4AB7-A6FD-294DFBC08D87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {83DA683F-A2C5-4AB7-A6FD-294DFBC08D87}.Debug|Any CPU.Build.0 = Debug|Any CPU + {83DA683F-A2C5-4AB7-A6FD-294DFBC08D87}.Release|Any CPU.ActiveCfg = Release|Any CPU + {83DA683F-A2C5-4AB7-A6FD-294DFBC08D87}.Release|Any CPU.Build.0 = Release|Any CPU + {F7DC6A70-907B-448A-A69D-4E2E80FA3FD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7DC6A70-907B-448A-A69D-4E2E80FA3FD3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7DC6A70-907B-448A-A69D-4E2E80FA3FD3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7DC6A70-907B-448A-A69D-4E2E80FA3FD3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal