-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathOpenFeatureAPIFactory.java
More file actions
53 lines (49 loc) · 1.85 KB
/
OpenFeatureAPIFactory.java
File metadata and controls
53 lines (49 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package dev.openfeature.sdk.isolated;
import dev.openfeature.sdk.OpenFeatureAPI;
/**
* Factory for creating isolated OpenFeature API instances.
*
* <p>Each instance returned by {@link #createAPI()} maintains its own state,
* including providers, evaluation context, hooks, event handlers, and
* transaction context propagators. Instances do not share state with the
* global singleton ({@link OpenFeatureAPI#getInstance()}) or with each other.
*
* <p>This class lives in a distinct package ({@code dev.openfeature.sdk.isolated})
* to make isolated instances intentionally less discoverable than the global
* singleton, reducing the chance of accidental use when the singleton would be
* appropriate.
*
* <p>This is useful for dependency injection frameworks, testing scenarios,
* and applications composed of multiple submodules requiring distinct providers.
*
* <p><strong>Spec references:</strong>
* <ul>
* <li>Requirement 1.8.1 — factory function for isolated instances</li>
* <li>Requirement 1.8.3 — factory in a distinct package/module</li>
* </ul>
*
* @apiNote This API is experimental and subject to change.
* @see <a href="https://openfeature.dev/specification/sections/flag-evaluation#18-isolated-api-instances">
* Spec §1.8 — Isolated API Instances</a>
*/
public final class OpenFeatureAPIFactory {
private OpenFeatureAPIFactory() {
// utility class
}
/**
* Creates a new, independent {@link OpenFeatureAPI} instance with fully
* isolated state.
*
* <p>Usage:
* <pre>{@code
* OpenFeatureAPI api = OpenFeatureAPIFactory.createAPI();
* api.setProvider(new MyProvider());
* Client client = api.getClient();
* }</pre>
*
* @return a new API instance
*/
public static OpenFeatureAPI createAPI() {
return new OpenFeatureAPI();
}
}