/// <summary> /// Registers an action to configure the <see cref="SweetAlertService"/> and add it as a scoped service to the specified <see cref="IServiceCollection"/>. /// </summary> /// <param name="services">The <see cref="IServiceCollection"/> to add the <see cref="SweetAlertService"/> to.</param> /// <param name="configureOptions">The action used to configure the options.</param> /// <returns></returns> public static IServiceCollection AddSweetAlert2(this IServiceCollection services, Action <SweetAlertServiceOptions> configureOptions) { if (configureOptions == null) { throw new ArgumentNullException(nameof(configureOptions)); } var options = new SweetAlertServiceOptions(); configureOptions(options); return(services.AddScoped(s => new SweetAlertService(s.GetRequiredService <IJSRuntime>(), options))); }
public SweetAlertService(IJSRuntime jSRuntime, SweetAlertServiceOptions options) { this.jSRuntime = jSRuntime; if (options == null) { return; } theme = options.Theme; colorSchemeThemes = options.ColorSchemeThemes .Select(kvp => new int[2] { (int)kvp.Key, (int)kvp.Value }) .ToArray(); }
public SweetAlertService(IJSRuntime jSRuntime, SweetAlertServiceOptions options) { _jSRuntime = jSRuntime; if (options == null) { return; } _theme = options.Theme; _colorSchemeThemes = options.ColorSchemeThemes .Select(kvp => new[] { (int)kvp.Key, (int)kvp.Value }) .ToArray(); if (options.DefaultOptions != null) { _defaultOptions = options.DefaultOptions; } _ = SendThemesToJs(); }