Repository navigation
Expand file tree
/
Copy pathFastReportServiceCollectionExtensions.cs
More file actions
71 lines (60 loc) · 2.31 KB
/
Copy pathFastReportServiceCollectionExtensions.cs
File metadata and controls
71 lines (60 loc) · 2.31 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using FastReport.Web;
using System;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.Extensions.DependencyInjection
{
public static partial class FastReportServiceCollectionExtensions
{
/// <summary>
/// Adds FastReport services to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection
/// </summary>
/// <param name="services"></param>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddFastReport(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
var options = new WebReportOptions();
AddFastReportPrivate(services, options);
return services;
}
/// <summary>
/// Adds FastReport services to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection
/// </summary>
/// <param name="services"></param>
/// <param name="setupAction"></param>
/// <exception cref="ArgumentNullException"></exception>
public static IServiceCollection AddFastReport(this IServiceCollection services, Action<WebReportOptions> setupAction)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
var options = new WebReportOptions();
setupAction(options);
AddFastReportPrivate(services, options);
return services;
}
private static void AddFastReportPrivate(IServiceCollection services, WebReportOptions options)
{
FastReport.Utils.Config.WebMode = true;
#if !WASM
ConfigureApplicationPart(services, options);
#else
AddWasmServices(services, options);
#endif
}
private static ServiceDescriptor GetServiceDescriptorFromCollection<T>(IServiceCollection services)
{
return services.LastOrDefault((ServiceDescriptor d) => d.Lifetime == ServiceLifetime.Singleton && d.ServiceType == typeof(T));
}
}
}