Refactor console client to new Govor.ConsoleClient project

Removed Govor.Console implementation and introduced a new Govor.ConsoleClient project with a modular command-based architecture. Added dependency injection, command dispatcher, middleware pipeline, logging, and interactive command support. Updated solution and project files to reflect the new structure.
This commit is contained in:
Artemy
2025-07-19 19:08:21 +07:00
parent ff873ae179
commit f524a9f0b7
21 changed files with 410 additions and 268 deletions
@@ -0,0 +1,47 @@
using System.Reflection;
using Govor.ConsoleClient.Commands;
using Govor.ConsoleClient.Services;
using Govor.ConsoleClient.Services.Middleware;
using Microsoft.Extensions.DependencyInjection;
namespace Govor.ConsoleClient;
public static class DependencyInjection
{
public static IServiceProvider Configure()
{
var services = new ServiceCollection();
// Регистрация команд
services.AddCommands();
// Сервисы
services.AddSingleton<CommandDispatcher>();
services.AddSingleton<InputPipeline>();
services.AddSingleton<ConsoleLogger>();
services.AddSingleton<ILogger>(sp => sp.GetRequiredService<ConsoleLogger>());
services.AddSingleton<CommandContext>();
services.AddSingleton<MiddlewarePipeline>();
// Middleware
services.AddSingleton<ICommandMiddleware, ExceptionHandlingMiddleware>();
return services.BuildServiceProvider();
}
public static IServiceCollection AddCommands(this IServiceCollection services)
{
var commandTypes = Assembly.GetExecutingAssembly()
.GetTypes()
.Where(t => typeof(ICommand).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract);
foreach (var type in commandTypes)
{
services.AddTransient(typeof(ICommand), type);
services.AddTransient(type); // Для прямого внедрения
}
return services;
}
}