// https://docs.asp.net/en/latest/mvc/controllers/dependency-injection.html#accessing-settings-from-a-controller public CredentialManager(IOptions <Settings_Email> optionsAccessor) { _settings = optionsAccessor.Value; // reads appsettings.json smtp = _settings.Host; port = _settings.Port; }
public EmailSink(string host, int port, string recipients, string subject, string credentials, IEventTextFormatter formatter, IOptions <Settings_Email> optionsAccessor) { this.formatter = formatter ?? new EventTextFormatter(); this.host = host; this.port = GuardPort(port); _settings = optionsAccessor.Value; // reads appsettings.json this.sender = new MailAddress(_settings.UserName); // see http://dotnetslackers.com/Community/blogs/kaushalparik/archive/2008/09/06/accessing-web-config-file-smtp-mail-settings-programmatically.aspx this.recipients.Add(GuardRecipients(recipients)); this.subject = subject ?? DefaultSubject; }