Skip to content

Commit aafdb43

Browse files
committed
feat(angular): add option for initial context injection
Signed-off-by: Lukas Reining <lukas.reining@codecentric.de>
1 parent b60c3df commit aafdb43

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/angular/projects/angular-sdk/src/lib/open-feature.module.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { InjectionToken, ModuleWithProviders, NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
3-
import { OpenFeature, Provider } from '@openfeature/web-sdk';
3+
import { EvaluationContext, OpenFeature, Provider } from '@openfeature/web-sdk';
4+
5+
export type EvaluationContextFactory = () => EvaluationContext;
46

57
export interface OpenFeatureConfig {
68
provider: Provider;
79
domainBoundProviders?: Record<string, Provider>;
10+
context?: EvaluationContext | EvaluationContextFactory;
811
}
912

1013
export const OPEN_FEATURE_CONFIG_TOKEN = new InjectionToken<OpenFeatureConfig>('OPEN_FEATURE_CONFIG_TOKEN');
@@ -16,7 +19,9 @@ export const OPEN_FEATURE_CONFIG_TOKEN = new InjectionToken<OpenFeatureConfig>('
1619
})
1720
export class OpenFeatureModule {
1821
static forRoot(config: OpenFeatureConfig): ModuleWithProviders<OpenFeatureModule> {
19-
OpenFeature.setProvider(config.provider);
22+
const context = typeof config.context === 'function' ? config.context() : config.context;
23+
OpenFeature.setProvider(config.provider, context);
24+
2025
if (config.domainBoundProviders) {
2126
Object.entries(config.domainBoundProviders).map(([domain, provider]) =>
2227
OpenFeature.setProvider(domain, provider),

0 commit comments

Comments
 (0)