Skip to content

Commit 5f357f6

Browse files
DeepRedManhOptimizely
authored andcommitted
Allow TransformAction to clone options
When the client is used to query different graph sources the transform action passed to CreateFromConfig can be used to manipulate the keys sent. However the changes are applied to the global options and doesnt reset after the client has finished its query. By introducing a behaviour it is possible to dictatate if the developer wants to be able to apply the transformation on a clone of the options. The default behaviour is that the current behavior where the options are global.
1 parent e6f75f2 commit 5f357f6

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

APIs/src/EpiServer.ContentGraph/Api/Querying/GraphQueryBuilder.cs

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ public static GraphQueryBuilder CreateFromConfig(Action<OptiGraphOptions> transf
4242
var httpClientFactory = ServiceLocator.Current.GetService(typeof(IHttpClientFactory)) as IHttpClientFactory;
4343
if (transformAction != null)
4444
{
45+
if (options.TransformActionBehaviour == TransformActionBehaviour.Clone)
46+
{
47+
var clonedOptions = (OptiGraphOptions)options.Clone();
48+
transformAction(clonedOptions);
49+
50+
return new GraphQueryBuilder(clonedOptions, httpClientFactory);
51+
}
52+
4553
transformAction(options);
4654
}
4755
if (options != null)

APIs/src/EpiServer.ContentGraph/Configuration/OptiGraphOptions.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace EPiServer.ContentGraph.Configuration
66
{
77
[Options]
8-
public class OptiGraphOptions
8+
public class OptiGraphOptions : ICloneable
99
{
1010
public const string ConfigSection = "Optimizely:ContentGraph";
1111

@@ -57,5 +57,12 @@ public string Authorization
5757
return $"epi-single {SingleKey}";
5858
}
5959
}
60+
61+
public TransformActionBehaviour TransformActionBehaviour { get; set; }
62+
63+
public object Clone()
64+
{
65+
return this.MemberwiseClone();
66+
}
6067
}
6168
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace EPiServer.ContentGraph.Configuration
8+
{
9+
/// <summary>
10+
/// Configures how OptiGraphOptions should handle the output of TransformAction when creating options
11+
/// </summary>
12+
public enum TransformActionBehaviour
13+
{
14+
/// <summary>
15+
/// Default, transform action changes the global options
16+
/// </summary>
17+
Default,
18+
/// <summary>
19+
/// Clone, transform action clones the options and applies transformation only on the clone
20+
/// </summary>
21+
Clone
22+
}
23+
}

0 commit comments

Comments
 (0)