Updated HttpClient setup to use named clients for API calls and DevExpress components, improving resource management and scalability. Scoped a default HttpClient for PdfViewer requirements. Removed ApiOptions configuration binding for simplification. Updated FontLoader to use IHttpClientFactory to align with modern best practices.
61 lines
2.6 KiB
C#
61 lines
2.6 KiB
C#
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
|
using EnvelopeGenerator.Server.Client.Services;
|
|
using EnvelopeGenerator.Server.Client.Options;
|
|
using DevExpress.Blazor.Reporting;
|
|
using DevExpress.XtraReports.Web.Extensions;
|
|
using DevExpress.DataAccess.Web;
|
|
using DevExpress.XtraReports.Services;
|
|
|
|
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
|
|
|
// Named HttpClient for API calls (both for services and DevExpress components)
|
|
builder.Services.AddHttpClient("EnvelopeGenerator.Server", client =>
|
|
{
|
|
client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress);
|
|
});
|
|
|
|
// Default HttpClient (DevExpress PdfViewer requires this)
|
|
builder.Services.AddScoped(sp => new HttpClient
|
|
{
|
|
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
|
|
});
|
|
|
|
// Configuration Options
|
|
builder.Services.Configure<PdfViewerOptions>(opts =>
|
|
builder.Configuration.GetSection(PdfViewerOptions.SectionName).Bind(opts));
|
|
|
|
// Business Services
|
|
builder.Services.AddScoped<DocumentService>();
|
|
builder.Services.AddScoped<AuthService>();
|
|
builder.Services.AddScoped<AnnotationService>();
|
|
builder.Services.AddScoped<EnvelopeReceiverService>();
|
|
builder.Services.AddScoped<SignatureService>();
|
|
builder.Services.AddScoped<SignatureCacheService>();
|
|
builder.Services.AddSingleton<AppVersionService>();
|
|
|
|
// DevExpress WASM
|
|
builder.Services.AddDevExpressWebAssemblyBlazorPdfViewer();
|
|
builder.Services.AddDevExpressWebAssemblyBlazorReportViewer();
|
|
|
|
builder.Services.AddDevExpressBlazorReportingWebAssembly(configure => {
|
|
configure.UseDevelopmentMode();
|
|
});
|
|
|
|
// Reporting Services
|
|
builder.Services.AddScoped<IDataSourceWizardJsonConnectionStorage, CustomDataSourceWizardJsonDataConnectionStorage>();
|
|
builder.Services.AddScoped<IJsonDataConnectionProviderFactory, CustomJsonDataConnectionProviderFactory>();
|
|
builder.Services.AddScoped<IObjectDataSourceWizardTypeProvider, ObjectDataSourceWizardCustomTypeProvider>();
|
|
|
|
DevExpress.Utils.DeserializationSettings.RegisterTrustedClass(typeof(EnvelopeGenerator.Server.Client.Data.DataItemList));
|
|
DevExpress.Utils.DeserializationSettings.RegisterTrustedClass(typeof(EnvelopeGenerator.Server.Client.PredefinedReports.Report));
|
|
|
|
builder.Services.AddSingleton<InMemoryReportStorageWebExtension>();
|
|
builder.Services.AddSingleton<ReportStorageWebExtension>(sp => sp.GetRequiredService<InMemoryReportStorageWebExtension>());
|
|
builder.Services.AddScoped<IReportProviderAsync, CustomReportProvider>();
|
|
|
|
ReportStorageWebExtension.RegisterExtensionGlobal(new InMemoryReportStorageWebExtension());
|
|
|
|
var host = builder.Build();
|
|
await FontLoader.LoadFonts(host.Services.GetRequiredService<IHttpClientFactory>(), new List<string> { "opensans.ttf" });
|
|
await host.RunAsync();
|