Переделал всё на DI

This commit is contained in:
ftc
2024-01-20 18:37:52 +03:00
parent 2a8348df44
commit d641de9689
5 changed files with 66 additions and 35 deletions
+8 -4
View File
@@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
@@ -7,6 +8,7 @@ using System.Threading.Tasks;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Types.ReplyMarkups;
using ZaoBot.Config;
using ZaoBot.OpenHab;
namespace ZaoBot
@@ -19,12 +21,14 @@ namespace ZaoBot
private JsonDocument config;
HttpClient http = new HttpClient();
OpenHabClient openhab;
IServiceProvider services;
public StatusMenuUserState(ITelegramBotClient botClient, JsonDocument config, OpenHabClient openhab)
public StatusMenuUserState(IServiceProvider services, ITelegramBotClient botClient, IConfig config, OpenHabClient openhab)
{
this.botClient = botClient;
this.config = config;
this.config = config.Data;
this.openhab = openhab;
this.services = services;
}
public async Task<IUserState> ProcessMessage(IUserState previous, Telegram.Bot.Types.Update e)
@@ -47,7 +51,7 @@ namespace ZaoBot
}
else if (e.Message.Text == CMD_BACK)
{
var newState = new MainMenuUserState(botClient, config, openhab);
var newState = services.GetRequiredService<MainMenuUserState>();
await newState.ProcessMessage(this, e);
return newState;
}