mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user