Переделал всё на DI
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
@@ -7,6 +8,7 @@ using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
using ZaoBot.Config;
|
||||
using ZaoBot.OpenHab;
|
||||
|
||||
namespace ZaoBot
|
||||
@@ -25,14 +27,16 @@ namespace ZaoBot
|
||||
private JsonDocument config;
|
||||
List<CameraConfigData> cameras;
|
||||
OpenHabClient openhab;
|
||||
IServiceProvider services;
|
||||
|
||||
public CamerasMenuUserState(ITelegramBotClient botClient, JsonDocument config, OpenHabClient openhab)
|
||||
public CamerasMenuUserState(IServiceProvider services, ITelegramBotClient botClient, IConfig config, OpenHabClient openhab)
|
||||
{
|
||||
this.botClient = botClient;
|
||||
this.config = config;
|
||||
this.config = config.Data;
|
||||
this.openhab = openhab;
|
||||
this.services = services;
|
||||
cameras = new List<CameraConfigData>();
|
||||
foreach (var element in config.RootElement.GetProperty("cameras").EnumerateObject())
|
||||
foreach (var element in this.config.RootElement.GetProperty("cameras").EnumerateObject())
|
||||
{
|
||||
var cam = new CameraConfigData()
|
||||
{
|
||||
@@ -47,7 +51,7 @@ namespace ZaoBot
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user