Skip to content

Commit 53bb9d9

Browse files
committed
Update README for multiprovider
1 parent d902d21 commit 53bb9d9

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed

README.md

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Task {
115115
|| [Hooks](#hooks) | Add functionality to various stages of the flag evaluation life-cycle. |
116116
|| [Tracking](#tracking) | Associate user actions with feature flag evaluations. |
117117
|| [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. |
119119
|| [Eventing](#eventing) | React to state changes in the provider or flag management system. |
120120
|| [Shutdown](#shutdown) | Gracefully clean up a provider during application shutdown. |
121121
|| [Extending](#extending) | Extend OpenFeature with custom providers and hooks. |
@@ -184,6 +184,89 @@ Logging customization is not yet available in the iOS SDK.
184184

185185
Support for named clients is not yet available in the iOS SDK.
186186

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+
import OpenFeature
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])
203+
204+
// Set the MultiProvider as the global provider
205+
await OpenFeatureAPI.shared.setProviderAndWait(provider: multiProvider)
206+
207+
// 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+
187270
### Eventing
188271

189272
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

Comments
 (0)