public static void AddServices(this IServiceCollection services, IConfiguration configuration)
        {
            var authParams = configuration.GetSection("Jwt")
                             .Get <AuthParameters>();

            EmailNotifyConfig emailConfig = configuration.GetSection("Notifiers")
                                            .GetSection("Sendgrid")
                                            .Get <EmailNotifyConfig>();

            services.AddSingleton <IAlertNotifier>(a => new EmailNotifier(emailConfig));
            services.AddScoped <IAuthService>(a => new AuthService(authParams));
            services.AddSingleton <IDataParser, DataParser>();
        }
Exemple #2
0
        public static SmtpEmailNotify CreateEmailSmtpNotify(EmailNotifyConfig cfg)
        {
            var emailNotify = ServiceProviderFactory.ServiceProvider.GetService <SmtpEmailNotify>();

            emailNotify.Enable    = cfg.Enable;
            emailNotify.OnFailure = cfg.OnFailure;
            emailNotify.OnSuccess = cfg.OnSuccess;
            emailNotify.OnWarning = cfg.OnWarning;

            cfg.OptionList.NullSafeSetTo <string>(s => emailNotify.From           = s, "from");
            cfg.OptionList.NullSafeSetTo <string>(s => emailNotify.To             = s, "to");
            cfg.OptionList.NullSafeSetTo <string>(s => emailNotify.Address        = s, "address");
            cfg.OptionList.NullSafeSetTo <string>(s => emailNotify.Domain         = s, "domain");
            cfg.OptionList.NullSafeSetTo <string>(s => emailNotify.UserName       = s, "user_name");
            cfg.OptionList.NullSafeSetTo <string>(s => emailNotify.Password       = s, "password");
            cfg.OptionList.NullSafeSetTo <string>(s => emailNotify.Authentication = s, "authentication");
            cfg.OptionList.NullSafeSetTo <bool>(s => emailNotify.EnableStarttls   = s, "enable_starttls");
            cfg.OptionList.NullSafeSetTo <string>(s => emailNotify.CC             = s, "cc");
            cfg.OptionList.NullSafeSetTo <string>(s => emailNotify.BCC            = s, "bcc");
            cfg.OptionList.NullSafeSetTo <int>(port => emailNotify.Port           = port, "port");

            return(emailNotify);
        }
 public EmailNotifier(EmailNotifyConfig config)
 {
     this.config = config ?? throw new ArgumentNullException(nameof(config));
 }