From abf616c1157641346bf7c5e067d4e5ff266a647b Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 29 Oct 2026 15:51:58 +0100 Subject: [PATCH] Add IRequestContext interface and RequestContext class Introduce the IRequestContext interface with an Origin property in the EnvelopeGenerator.Application.Common.Interfaces namespace. Implement this interface in the new RequestContext class within EnvelopeGenerator.Server.Services, using IHttpContextAccessor to access the Origin header. Register IRequestContext with the DI container in Program.cs using AddScoped. Update using directives to include necessary namespaces and reorganize for clarity. --- .../Common/Interfaces/IRequestContext.cs | 12 ++++++++++++ .../EnvelopeGenerator.Server/Program.cs | 4 ++++ .../Services/RequestContext.cs | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 EnvelopeGenerator.Application/Common/Interfaces/IRequestContext.cs create mode 100644 EnvelopeGenerator.Server/EnvelopeGenerator.Server/Services/RequestContext.cs diff --git a/EnvelopeGenerator.Application/Common/Interfaces/IRequestContext.cs b/EnvelopeGenerator.Application/Common/Interfaces/IRequestContext.cs new file mode 100644 index 00000000..e95559b6 --- /dev/null +++ b/EnvelopeGenerator.Application/Common/Interfaces/IRequestContext.cs @@ -0,0 +1,12 @@ +namespace EnvelopeGenerator.Application.Common.Interfaces; + +/// +/// +/// +public interface IRequestContext +{ + /// + /// + /// + string? Origin { get; } +} \ No newline at end of file diff --git a/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Program.cs b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Program.cs index 577136b1..3698a76b 100644 --- a/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Program.cs +++ b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Program.cs @@ -8,6 +8,7 @@ using DigitalData.Core.Application; using DigitalData.EmailProfilerDispatcher; using DigitalData.UserManager.DependencyInjection; using EnvelopeGenerator.Application; +using EnvelopeGenerator.Application.Common.Interfaces; using EnvelopeGenerator.Application.Common.Interfaces.Doc; using EnvelopeGenerator.Domain.Constants; using EnvelopeGenerator.Infrastructure; @@ -19,6 +20,7 @@ using EnvelopeGenerator.Server.Client.Services; using EnvelopeGenerator.Server.Components; using EnvelopeGenerator.Server.Models; using EnvelopeGenerator.Server.Options; +using EnvelopeGenerator.Server.Services; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Localization; @@ -392,6 +394,8 @@ try builder.Services.Configure( builder.Configuration.GetSection("PdfViewerOptions")); + builder.Services.AddScoped(); + var app = builder.Build(); deferredProvider.Factory = () => app.Services; diff --git a/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Services/RequestContext.cs b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Services/RequestContext.cs new file mode 100644 index 00000000..b679db80 --- /dev/null +++ b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Services/RequestContext.cs @@ -0,0 +1,18 @@ +using EnvelopeGenerator.Application.Common.Interfaces; + +namespace EnvelopeGenerator.Server.Services; + +/// +/// +/// +/// +public sealed class RequestContext( + IHttpContextAccessor HttpContextAccessor) : IRequestContext +{ + /// + /// + /// + public string? Origin => + HttpContextAccessor.HttpContext? + .Request.Headers.Origin.ToString(); +}