/// <summary> /// Adds <see cref="IEmailer"/> service to the service collection. This method assumes you have added configuration in the appsettings.json. /// </summary> /// <param name="services">Service collection.</param> /// <param name="configuration">Configuration.</param> /// <returns><see cref="IServiceCollection"/>.</returns> public static IServiceCollection AddSendGridEmailer(this IServiceCollection services, IConfiguration configuration) { SendGridOptions options = new SendGridOptions(); void configureOptions(SendGridOptions o) => configuration.GetSection("SendGridSettings").Bind(o); services.Configure((Action <SendGridOptions>)configureOptions); services.AddTransient <IEmailer, SendGridEmailer>(); return(services); }
/// <summary> /// Initializes a new instance of <see cref="Emailer"/> class. /// </summary> /// <param name="serviceProvider">Service provider.</param> /// <param name="options">Options.</param> public SendGridEmailer(IServiceProvider serviceProvider, IOptions <SendGridOptions> options) { m_serviceProvider = serviceProvider; m_options = options.Value; }