feat: begin working on console app
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.1" />
|
||||
<PackageReference Include="Spectre.Console" Version="0.49.1" />
|
||||
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -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<object> func)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(func);
|
||||
|
||||
_builder.ConfigureServices((_, services) => services.AddSingleton(service, _ => func()));
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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!");
|
||||
@@ -0,0 +1,4 @@
|
||||
global using Microsoft.Extensions.DependencyInjection;
|
||||
global using Microsoft.Extensions.Hosting;
|
||||
|
||||
global using Spectre.Console.Cli;
|
||||
Reference in New Issue
Block a user