Переделал всё на DI
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Args;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
using ZaoBot.Config;
|
||||
using ZaoBot.OpenHab;
|
||||
|
||||
namespace ZaoBot
|
||||
@@ -23,11 +23,13 @@ namespace ZaoBot
|
||||
private JsonDocument config;
|
||||
HttpClient http = new HttpClient();
|
||||
OpenHabClient openhab;
|
||||
IServiceProvider services;
|
||||
|
||||
public MainMenuUserState(ITelegramBotClient botClient, JsonDocument config, OpenHabClient openhab)
|
||||
public MainMenuUserState(IServiceProvider services, ITelegramBotClient botClient, IConfig config, OpenHabClient openhab)
|
||||
{
|
||||
this.services = services;
|
||||
this.botClient = botClient;
|
||||
this.config = config;
|
||||
this.config = config.Data;
|
||||
this.openhab = openhab;
|
||||
}
|
||||
|
||||
@@ -61,13 +63,13 @@ namespace ZaoBot
|
||||
}
|
||||
else if (e.Message.Text == CMD_STATUS)
|
||||
{
|
||||
var newState = new StatusMenuUserState(botClient, config, openhab);
|
||||
var newState = services.GetRequiredService<StatusMenuUserState>();
|
||||
await newState.ProcessMessage(this, e);
|
||||
return newState;
|
||||
}
|
||||
else if (e.Message.Text == CMD_CAMERAS)
|
||||
{
|
||||
var newState = new CamerasMenuUserState(botClient, config, openhab);
|
||||
var newState = services.GetRequiredService<CamerasMenuUserState>();
|
||||
await newState.ProcessMessage(this, e);
|
||||
return newState;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user