0
我的asp.net靜態構造函數發送郵件遷移asp.net網站的API來asp.net核心
時,這是獲取調用static EmailHelper()
{
//load configuration from config file
int intSmtpPort = 0;
int.TryParse(WebConfigurationManager.AppSettings["smtpport"], out intSmtpPort);
host = WebConfigurationManager.AppSettings["smtpclient"];
port = intSmtpPort;
user = WebConfigurationManager.AppSettings["username"];
password = WebConfigurationManager.AppSettings["password"];
fromEmail = WebConfigurationManager.AppSettings["frommail"];
}
我的asp.net核心靜態構造函數的類會拋出錯誤,因爲它應該是參但我需要使用配置
static EmailHelper(IOptions<SmtpConfig> smtpConfig)
{
int intSmtpPort = 0;
int.TryParse(SmtpConfig.smtpport, out intSmtpPort);
host = SmtpConfig.smtpclient;
port = intSmtpPort;
user = SmtpConfig.username;
password = SmtpConfig.password;
fromEmail = SmtpConfig.frommail;
}
如果我使用公共構造函數,它不會被調用。我該怎麼辦?有沒有另一種方法來注入配置設置在我的課而不使用依賴注入?
你可以讓這個類變成一個實例類型而不是靜態類嗎? – AperioOculus