-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathExtensionMethods.cs
39 lines (36 loc) · 1.77 KB
/
ExtensionMethods.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.JSInterop;
namespace CurrieTechnologies.Razor.SweetAlert2
{
/// <summary>
/// Collection of methods that extend other classes.
/// </summary>
public static class ExtensionMethods
{
/// <summary>
/// Adds the <see cref="SweetAlertService" /> 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>
/// <returns>The original <see cref="IServiceCollection" />.</returns>
public static IServiceCollection AddSweetAlert2(this IServiceCollection services)
{
return services.AddScoped<SweetAlertService>();
}
/// <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));
}
}
}