From 7d09df9ee6cf347c6b888bc8726a87940b493ad4 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 21 Jul 2025 11:31:40 +0530 Subject: [PATCH] LP changes to isolated config per request --- .../IServiceCollectionExtensions.cs | 4 ++-- .../Configuration/LivePreviewConfig.cs | 20 +++++++++++++++++++ Contentstack.Core/ContentstackClient.cs | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Contentstack.AspNetCore/IServiceCollectionExtensions.cs b/Contentstack.AspNetCore/IServiceCollectionExtensions.cs index 628fa12e..4c7092ae 100644 --- a/Contentstack.AspNetCore/IServiceCollectionExtensions.cs +++ b/Contentstack.AspNetCore/IServiceCollectionExtensions.cs @@ -25,7 +25,7 @@ public static IServiceCollection AddContentstack(this IServiceCollection service { services.AddOptions(); services.Configure(configuration.GetSection("ContentstackOptions")); - services.TryAddTransient(); + services.AddScoped(); return services; } @@ -39,7 +39,7 @@ public static IServiceCollection AddContentstack(this IServiceCollection service { services.AddOptions(); services.Configure(configuration.GetSection("ContentstackOptions")); - services.TryAddTransient(); + services.AddScoped(); return services; } } diff --git a/Contentstack.Core/Configuration/LivePreviewConfig.cs b/Contentstack.Core/Configuration/LivePreviewConfig.cs index 18670ca5..cc2560c8 100644 --- a/Contentstack.Core/Configuration/LivePreviewConfig.cs +++ b/Contentstack.Core/Configuration/LivePreviewConfig.cs @@ -14,5 +14,25 @@ public class LivePreviewConfig internal JObject PreviewResponse { get; set; } public string ReleaseId {get; set;} public string PreviewTimestamp {get; set;} + + /// + /// Creates a deep clone of the LivePreviewConfig for request isolation + /// + public LivePreviewConfig Clone() + { + return new LivePreviewConfig + { + ManagementToken = this.ManagementToken, + PreviewToken = this.PreviewToken, + Enable = this.Enable, + Host = this.Host, + LivePreview = this.LivePreview, + ContentTypeUID = this.ContentTypeUID, + EntryUID = this.EntryUID, + PreviewResponse = this.PreviewResponse?.DeepClone() as JObject, + ReleaseId = this.ReleaseId, + PreviewTimestamp = this.PreviewTimestamp + }; + } } } diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index 69dd881a..11eda041 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -115,7 +115,7 @@ public ContentstackClient(IOptions options) this.SetConfig(cnfig); if (_options.LivePreview != null) { - this.LivePreviewConfig = _options.LivePreview; + this.LivePreviewConfig = _options.LivePreview.Clone(); } else {