@@ -166,7 +166,7 @@ public Optimizely(string datafile,
166166#if USE_ODP
167167 // No need to setup notification for datafile updates. This constructor
168168 // is for hardcoded datafile which should not be changed using this method.
169- OdpManager . UpdateSettings ( config . PublicKeyForOdp , config . HostForOdp ,
169+ OdpManager ? . UpdateSettings ( config . PublicKeyForOdp , config . HostForOdp ,
170170 config . Segments . ToList ( ) ) ;
171171#endif
172172 }
@@ -219,29 +219,28 @@ public Optimizely(ProjectConfigManager configManager,
219219 InitializeComponents ( eventDispatcher , logger , errorHandler , userProfileService ,
220220 notificationCenter , eventProcessor , defaultDecideOptions , odpManager ) ;
221221
222- if ( ProjectConfigManager . CachedProjectConfig == null )
222+ var projectConfig = ProjectConfigManager . CachedProjectConfig ;
223+
224+ if ( ProjectConfigManager . CachedProjectConfig != null )
223225 {
224- return ;
226+ // in case Project config is instantly available
227+ OdpManager ? . UpdateSettings ( projectConfig . PublicKeyForOdp , projectConfig . HostForOdp ,
228+ projectConfig . Segments . ToList ( ) ) ;
225229 }
226-
227- var projectConfig = ProjectConfigManager . CachedProjectConfig ;
228-
229- // in case if notification is lost.
230- OdpManager ? . UpdateSettings ( projectConfig . PublicKeyForOdp , projectConfig . HostForOdp ,
231- projectConfig . Segments . ToList ( ) ) ;
232-
233230 if ( ProjectConfigManager . SdkKey != null )
234231 {
235- NotificationCenterRegistry .
236- GetNotificationCenter ( ProjectConfigManager . SdkKey , logger ) ? .
237- AddNotification ( NotificationCenter . NotificationType . OptimizelyConfigUpdate ,
238- ( ) =>
239- {
240- OdpManager ? . UpdateSettings ( projectConfig . PublicKeyForOdp ,
241- projectConfig . HostForOdp ,
242- projectConfig . Segments . ToList ( ) ) ;
243- } ) ;
232+ NotificationCenterRegistry . GetNotificationCenter ( configManager . SdkKey , logger ) ? .
233+ AddNotification ( NotificationCenter . NotificationType . OptimizelyConfigUpdate ,
234+ ( ) =>
235+ {
236+ projectConfig = ProjectConfigManager . CachedProjectConfig ;
237+
238+ OdpManager ? . UpdateSettings ( projectConfig . PublicKeyForOdp ,
239+ projectConfig . HostForOdp ,
240+ projectConfig . Segments . ToList ( ) ) ;
241+ } ) ;
244242 }
243+
245244#else
246245 InitializeComponents ( eventDispatcher , logger , errorHandler , userProfileService ,
247246 notificationCenter , eventProcessor , defaultDecideOptions ) ;
@@ -457,7 +456,7 @@ private Variation GetVariation(string experimentKey, string userId, ProjectConfi
457456 return null ;
458457 userAttributes = userAttributes ?? new UserAttributes ( ) ;
459458
460- var userContext = CreateUserContext ( userId , userAttributes ) ;
459+ var userContext = CreateUserContextCopy ( userId , userAttributes ) ;
461460 var variation = DecisionService . GetVariation ( experiment , userContext , config ) ? .
462461 ResultObject ;
463462 var decisionInfo = new Dictionary < string , object >
@@ -586,7 +585,7 @@ public virtual bool IsFeatureEnabled(string featureKey, string userId,
586585 bool featureEnabled = false ;
587586 var sourceInfo = new Dictionary < string , string > ( ) ;
588587 var decision = DecisionService .
589- GetVariationForFeature ( featureFlag , CreateUserContext ( userId , userAttributes ) ,
588+ GetVariationForFeature ( featureFlag , CreateUserContextCopy ( userId , userAttributes ) ,
590589 config ) .
591590 ResultObject ;
592591 var variation = decision ? . Variation ;
@@ -706,7 +705,7 @@ public virtual T GetFeatureVariableValueForType<T>(string featureKey, string var
706705 var featureEnabled = false ;
707706 var variableValue = featureVariable . DefaultValue ;
708707 var decision = DecisionService .
709- GetVariationForFeature ( featureFlag , CreateUserContext ( userId , userAttributes ) ,
708+ GetVariationForFeature ( featureFlag , CreateUserContextCopy ( userId , userAttributes ) ,
710709 config ) .
711710 ResultObject ;
712711
@@ -892,6 +891,24 @@ public OptimizelyUserContext CreateUserContext(string userId,
892891 return new OptimizelyUserContext ( this , userId , userAttributes , ErrorHandler , Logger ) ;
893892 }
894893
894+ private OptimizelyUserContext CreateUserContextCopy ( string userId ,
895+ UserAttributes userAttributes = null
896+ )
897+ {
898+ var inputValues = new Dictionary < string , string >
899+ {
900+ {
901+ USER_ID , userId
902+ } ,
903+ } ;
904+
905+ if ( ! ValidateStringInputs ( inputValues ) )
906+ return null ;
907+
908+
909+ return new OptimizelyUserContext ( this , userId , userAttributes , null , null , ErrorHandler , Logger , shouldIdentifyUser : false ) ;
910+ }
911+
895912 /// <summary>
896913 /// Returns a decision result ({@link OptimizelyDecision}) for a given flag key and a user context, which contains all data required to deliver the flag.
897914 /// <ul>
@@ -1276,7 +1293,7 @@ public OptimizelyJSON GetAllFeatureVariables(string featureKey, string userId,
12761293
12771294 var featureEnabled = false ;
12781295 var decisionResult = DecisionService . GetVariationForFeature ( featureFlag ,
1279- CreateUserContext ( userId , userAttributes ) , config ) ;
1296+ CreateUserContextCopy ( userId , userAttributes ) , config ) ;
12801297 var variation = decisionResult . ResultObject ? . Variation ;
12811298
12821299 if ( variation != null )
0 commit comments