Вот так:
Код: Выделить всё
Configuration.GetConnectionString("HangfireDBConn")
appSettings.json:
Код: Выделить всё
"NotifySettings": {
"DbConnection": "abc",
"Email": "abc@domain.com",
"SMTPPort": "5605"
}
Код: Выделить всё
public class NotifySettings
{
public string DbConnection { get; set; }
public string Email { get; set; }
public string SMTPPort { get; set; }
}
Код: Выделить всё
public class DatabaseUtil : IDatabaseUtil
{
private static NotifySettings _NotifySettings;
public DatabaseUtil(IConfiguration _iconfig)
{
_NotifySettings = _iconfig.GetSection("NotifySettings").Get();
}
public static String ConnectToDatabase()
{
return "MESSAGE :" + _NotifySettings.DbConnection;
}
}
}
Код: Выделить всё
services.AddScoped();
Да, я могу, но это не лучший способ!
Присоединяйтесь к моему мозговому штурму

Код: Выделить всё
DatabaseUtils.connect();
Что вы думаете о моем приближении? Какой из них лучше всего подходит для этого случая?
Подробнее здесь: https://stackoverflow.com/questions/619 ... yinjection