You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+84-1Lines changed: 84 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,7 +115,7 @@ Task {
115
115
| ✅ |[Hooks](#hooks)| Add functionality to various stages of the flag evaluation life-cycle. |
116
116
| ❌ |[Tracking](#tracking)| Associate user actions with feature flag evaluations. |
117
117
| ❌ |[Logging](#logging)| Integrate with popular logging packages. |
118
-
|❌|[Named clients](#named-clients)| Utilize multiple providers in a single application. |
118
+
|✅|[MultiProvider](#multiprovider)| Utilize multiple providers in a single application. |
119
119
| ✅ |[Eventing](#eventing)| React to state changes in the provider or flag management system. |
120
120
| ❌ |[Shutdown](#shutdown)| Gracefully clean up a provider during application shutdown. |
121
121
| ✅ |[Extending](#extending)| Extend OpenFeature with custom providers and hooks. |
@@ -184,6 +184,89 @@ Logging customization is not yet available in the iOS SDK.
184
184
185
185
Support for named clients is not yet available in the iOS SDK.
186
186
187
+
### MultiProvider
188
+
189
+
The `MultiProvider` allows you to combine multiple feature flag providers into a single provider, enabling you to use different providers for different flags or implement fallback mechanisms. This is useful when migrating between providers, implementing A/B testing across providers, or ensuring high availability.
190
+
191
+
#### Basic Usage
192
+
193
+
```swift
194
+
importOpenFeature
195
+
196
+
Task {
197
+
// Create individual providers
198
+
let primaryProvider =PrimaryProvider()
199
+
let fallbackProvider =FallbackProvider()
200
+
201
+
// Create a MultiProvider with default FirstFoundStrategy
202
+
let multiProvider =MultiProvider(providers: [primaryProvider, fallbackProvider])
// Use flags normally - the MultiProvider will handle provider selection
208
+
let client = OpenFeatureAPI.shared.getClient()
209
+
let flagValue = client.getBooleanValue(key: "my-flag", defaultValue: false)
210
+
}
211
+
```
212
+
213
+
#### Evaluation Strategies
214
+
215
+
The `MultiProvider` supports different strategies for evaluating flags across multiple providers:
216
+
217
+
##### FirstFoundStrategy (Default)
218
+
219
+
The `FirstFoundStrategy` evaluates providers in order and returns the first result that doesn't indicate "flag not found". If a provider returns an error other than "flag not found", that error is returned immediately.
220
+
221
+
```swift
222
+
let multiProvider =MultiProvider(
223
+
providers: [primaryProvider, fallbackProvider],
224
+
strategy: FirstFoundStrategy()
225
+
)
226
+
```
227
+
228
+
##### FirstSuccessfulStrategy
229
+
230
+
The `FirstSuccessfulStrategy` evaluates providers in order and returns the first successful result (no error). Unlike `FirstFoundStrategy`, it continues to the next provider if any error occurs, including "flag not found".
231
+
232
+
```swift
233
+
let multiProvider =MultiProvider(
234
+
providers: [primaryProvider, fallbackProvider],
235
+
strategy: FirstSuccessfulStrategy()
236
+
)
237
+
```
238
+
239
+
#### Use Cases
240
+
241
+
**Provider Migration:**
242
+
```swift
243
+
// Gradually migrate from OldProvider to NewProvider
244
+
let multiProvider =MultiProvider(providers: [
245
+
NewProvider(), // Check new provider first
246
+
OldProvider() // Fall back to old provider
247
+
])
248
+
```
249
+
250
+
**High Availability:**
251
+
```swift
252
+
// Use multiple providers for redundancy
253
+
let multiProvider =MultiProvider(providers: [
254
+
RemoteProvider(),
255
+
LocalCacheProvider(),
256
+
StaticProvider()
257
+
])
258
+
```
259
+
260
+
**Environment-Specific Providers:**
261
+
```swift
262
+
// Different providers for different environments
263
+
let providers = [
264
+
EnvironmentProvider(environment: "production"),
265
+
DefaultProvider()
266
+
]
267
+
let multiProvider =MultiProvider(providers: providers)
268
+
```
269
+
187
270
### Eventing
188
271
189
272
Events allow you to react to state changes in the provider or underlying flag management system, such as flag definition changes, provider readiness, or error conditions.
0 commit comments