Как возвращать переменные из классов?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Brusketta.src.Controllers.Interfaces
{
internal interface IAuthorizations
{
void Authorization();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Brusketta.src.Controllers.Interfaces
{
internal interface IAuthorizationTokens
{
string Access_token_Vk { set; get; }
string Version_VkAPI { set; get; }
string? Token_Telegram { set; get; }
List<string> IdTelegram { set; get; }
}
}
using Brusketta.src.Controllers.Interfaces;
using Microsoft.Extensions.Configuration;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Brusketta.src.Controllers.Models
{
internal class Authorizations : IAuthorizations, IAuthorizationTokens
{
public string Access_token_Vk { set; get; }
public string Version_VkAPI { set; get; }
public string? Token_Telegram { set; get; }
public List<string> IdTelegram { set; get; } = new List<string>();
public void Authorization()
{
var log = Log.ForContext<Authorizations>();
try
{
var config = new ConfigurationBuilder()
.AddJsonFile("Properties/secretKey.json")
.Build();
Access_token_Vk = config.GetValue<string>("VCSecret:access_token");
Version_VkAPI = config.GetValue<string>("VCSecret:version");
Token_Telegram = config.GetValue<string>("TelegramSecret:token");
IdTelegram.Add(config.GetValue<string>("TelegramId:id_1"));
IdTelegram.Add(config.GetValue<string>("TelegramId:id_2"));
}
catch (Exception ex)
{
log.Error("Конфигурационный файл не доступен", ex);
}
log.Information(Access_token_Vk);
log.Information(Version_VkAPI);
log.Information(Token_Telegram);
foreach (var id in IdTelegram)
{
log.Information($"{id}");
}
}
}
}
using Brusketta.src.Controllers.Interfaces;
using Brusketta.src.Controllers.Models;
using Microsoft.Extensions.Configuration;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
[assembly: InternalsVisibleTo("Brusketta_Tests")]
namespace Brusketta.src.Controllers
{
internal class AuthorizationController
{
public IAuthorizations Authorizations { get; set; }
public AuthorizationController(IAuthorizations _authorizations) { this.Authorizations = _authorizations; }
public void Authorization()
{
var log = Log.ForContext<AuthorizationController>();
log.Information("Start");
Authorizations.Authorization();
}
}
}
using Brusketta.src.Controllers.Interfaces;
using Brusketta.src.Controllers.Models;
using Microsoft.Extensions.Configuration;
using Serilog;
using System.Net;
namespace Brusketta.src.Controllers
{
internal class Controller
{
public async Task RunController()
{
var log = Log.ForContext<Controller>();
log.Information("Start");
AuthorizationController authorizationController=new AuthorizationController(new Authorizations());
authorizationController.Authorization();
log.Information("Token finded: ");
}
}
}
Все работает, выводит в консоль, но как получить эти данные в класс Controller не знаю.
Запутался. Данные interface IAuthorizationTokens, видны только в классе его реализующем.