Read custom settings from the appsettings.json (MVC .NET Core) WITHOUT using DI.
Budget: $10 – $30 USD
Hi,
*******
NOTE: I know it can be done using the dependency injections approach inside controllers construction. however, I want to load the settings without injecting anything into the controller constructor.
in other words, I want to read the setting from any class without the need to inject the setting into controllers.
*******
I have this structure in my asspsetting.json
"SOSetting": {
"EMailSetting": {
"Server": "",
"Port": "",
"User": "",
"Pwd": "",
"Secure": true,
"From": "",
"Name": ""
},
"SMSSetting": {
"Gate": "",
"User": "",
"Pwd": "",
"Sender": ""
},
"ChatSetting": {
"Gate": "",
"Instance": ""
}
}
I want to load this settings into the classes below:
public class EMailSetting
{
public EMailSetting()
{
}
public string Server { get; set; }
public string Port { get; set; }
public string User { get; set; }
public string Pwd { get; set; }
public bool Secure { get; set; }
public string From { get; set; }
public string Name { get; set; }
}
public class SMSSetting
{
public string Gate { get; set; }
public string User { get; set; }
public string Pwd { get; set; }
public string Sender { get; set; }
}
public class ChatSetting
{
public string Gate { get; set; }
public string Instance { get; set; }
}
*******
NOTE: I know it can be done using the dependency injections approach inside controllers construction. however, I want to load the settings without injecting anything into the controller constructor.
in other words, I want to read the setting from any class without the need to inject the setting into controllers.
*******
I have this structure in my asspsetting.json
"SOSetting": {
"EMailSetting": {
"Server": "",
"Port": "",
"User": "",
"Pwd": "",
"Secure": true,
"From": "",
"Name": ""
},
"SMSSetting": {
"Gate": "",
"User": "",
"Pwd": "",
"Sender": ""
},
"ChatSetting": {
"Gate": "",
"Instance": ""
}
}
I want to load this settings into the classes below:
public class EMailSetting
{
public EMailSetting()
{
}
public string Server { get; set; }
public string Port { get; set; }
public string User { get; set; }
public string Pwd { get; set; }
public bool Secure { get; set; }
public string From { get; set; }
public string Name { get; set; }
}
public class SMSSetting
{
public string Gate { get; set; }
public string User { get; set; }
public string Pwd { get; set; }
public string Sender { get; set; }
}
public class ChatSetting
{
public string Gate { get; set; }
public string Instance { get; set; }
}