Repository navigation
Expand file tree
/
Copy pathFastReportServiceCollectionExtensions.Backend.cs
More file actions
66 lines (55 loc) · 2.5 KB
/
Copy pathFastReportServiceCollectionExtensions.Backend.cs
File metadata and controls
66 lines (55 loc) · 2.5 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
using FastReport.Code;
using FastReport.Web;
using FastReport.Web.Services;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.Extensions.DependencyInjection
{
public static partial class FastReportServiceCollectionExtensions
{
private static void ConfigureApplicationPart(IServiceCollection services, WebReportOptions options)
{
var manager = GetServiceFromCollection<ApplicationPartManager>(services);
if (manager != null)
{
var curAssembly = typeof(FastReportServiceCollectionExtensions).Assembly;
var curAssemblyName = curAssembly.GetName().Name;
var frAppPart = manager.ApplicationParts.FirstOrDefault(apPart => apPart.Name == curAssemblyName);
if (frAppPart == null)
{
// Register this assembly as part of user application
var assemblyPart = new AssemblyPart(curAssembly);
manager.ApplicationParts.Add(assemblyPart);
}
#if DEBUG // TODO: fix
// Then we can use new controllers
FastReportOptions.UseNewControllers = true;
#endif
AddFastReportWebServices(services, options);
}
FastReportGlobal.InternalCacheOptions = options.CacheOptions;
}
private static void AddFastReportWebServices(IServiceCollection services, WebReportOptions options)
{
services.TryAddSingleton<IResourceLoader, InternalResourceLoader>();
services.TryAddSingleton<IDesignerUtilsService, DesignerUtilsService>();
services.TryAddSingleton<IReportService, ReportService>();
#if DESIGNER
services.TryAddSingleton<IReportDesignerService, ReportDesignerService>();
#endif
services.TryAddSingleton<IConnectionsService, ConnectionService>();
services.TryAddSingleton<ITextEditService, TextEditService>();
services.TryAddSingleton<IExportsService, ExportService>();
services.TryAddSingleton<IPrintService, PrintService>();
}
// possible memory leaks, be careful!
private static T GetServiceFromCollection<T>(IServiceCollection services)
{
return (T)(GetServiceDescriptorFromCollection<T>(services)?.ImplementationInstance);
}
}
}