Breaking changes
Oversikt over breaking changes introdusert i App Nuget-pakker i v3.0.0.
We have added a new PDF handler to make it possible to hide pages and components in PDF.
The new version of the Altinn.App.* packages have breaking changes:
Updating to this version will require changes in multiple files.
- Updated package dependencies
Navigate to you application repository and findApp.csproj
in theApp
folder.
Update nuget dependencies inApp.csproj
to version 3.0.0.<PackageReference Include="Altinn.App.Api" Version="3.0.0" /> <PackageReference Include="Altinn.App.Common" Version="3.0.0" /> <PackageReference Include="Altinn.App.PlatformServices" Version="3.0.0" />
- Create a new file for a new class called PdfHandler in the logic/Print folder File from template
using System.Threading.Tasks; using Altinn.App.Common.Models; namespace Altinn.App.AppLogic.Print { /// <summary> /// Handler for formatting PDF. /// </summary> public class PdfHandler { /// <summary> /// Method to format PDF dynamic /// </summary> /// <param name="layoutSettings">the layoutsettings</param> /// <param name="data">data object</param> public async Task<LayoutSettings> FormatPdf(LayoutSettings layoutSettings, object data) { return await Task.FromResult(layoutSettings); } } }
- Changes to the App.cs file
Add usingAdd a new private field below InstantiationHandlerusing Altinn.App.AppLogic.Print; using Microsoft.Extensions.Options; using Microsoft.AspNetCore.Http; using Altinn.App.Services.Configuration;
Change constructor from:private readonly PdfHandler _pdfHandler;
to:public App( IAppResources appResourcesService, ILogger<App> logger, IData dataService, IProcess processService, IPDF pdfService, IProfile profileService, IRegister registerService, IPrefill prefillService, IInstance instanceService ) : base(appResourcesService, logger, dataService, processService, pdfService, prefillService, instanceService)
Add methodpublic App( IAppResources appResourcesService, ILogger<App> logger, IData dataService, IProcess processService, IPDF pdfService, IProfile profileService, IRegister registerService, IPrefill prefillService, IInstance instanceService, IOptions<GeneralSettings> settings, IText textService, IHttpContextAccessor httpContextAccessor) : base( appResourcesService, logger, dataService, processService, pdfService, prefillService, instanceService, registerService, settings, profileService, textService, httpContextAccessor) { _logger = logger; _validationHandler = new ValidationHandler(httpContextAccessor); _calculationHandler = new CalculationHandler(); _instantiationHandler = new InstantiationHandler(profileService, registerService); _pdfHandler = new PdfHandler(); }
/// <summary> /// Hook to run logic to hide pages or components when generatring PDF /// </summary> /// <param name="layoutSettings">The layoutsettings. Can be null and need to be created in method</param> /// <param name="data">The data that there is generated PDF from</param> /// <returns>Layoutsetting with possible hidden fields or pages</returns> public override async Task<LayoutSettings> FormatPdf(LayoutSettings layoutSettings, object data) { return await _pdfHandler.FormatPdf(layoutSettings, data); }