-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
89 lines (77 loc) · 2.84 KB
/
Copy pathProgram.cs
File metadata and controls
89 lines (77 loc) · 2.84 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using Replane;
Console.WriteLine("=== Replane Context & Overrides Example ===\n");
// Create client with a default context
// This context is merged with per-request context
await using var client = new ReplaneClient(new ReplaneClientOptions
{
// Default context - applied to all config reads
Context = new ReplaneContext
{
["app_version"] = "2.0.0",
["platform"] = "console"
},
// Defaults for demo purposes
Defaults = new Dictionary<string, object?>
{
["premium-feature"] = false,
["rate-limit"] = 100,
["welcome-message"] = "Hello!"
}
});
try
{
await client.ConnectAsync(new ConnectOptions
{
BaseUrl = Environment.GetEnvironmentVariable("REPLANE_BASE_URL")
?? "https://your-replane-server.com",
SdkKey = Environment.GetEnvironmentVariable("REPLANE_SDK_KEY")
?? "your-sdk-key"
});
Console.WriteLine("Connected to Replane server.\n");
}
catch (ReplaneException ex)
{
Console.WriteLine($"Note: Running with defaults only ({ex.Message})\n");
}
// Simulate different users
var users = new[]
{
new { Id = "user-001", Plan = "free", Region = "us-east" },
new { Id = "user-002", Plan = "premium", Region = "us-west" },
new { Id = "user-003", Plan = "enterprise", Region = "eu-west" },
};
Console.WriteLine("Evaluating configs for different users:\n");
Console.WriteLine(new string('-', 60));
foreach (var user in users)
{
// Create user-specific context
var userContext = new ReplaneContext
{
["user_id"] = user.Id,
["plan"] = user.Plan,
["region"] = user.Region
};
// Get configs with user context
// The user context is merged with the default context from options
var premiumFeature = client.Get<bool>("premium-feature", userContext);
var rateLimit = client.Get<int>("rate-limit", userContext);
var welcomeMessage = client.Get<string>("welcome-message", userContext);
Console.WriteLine($"User: {user.Id} (Plan: {user.Plan}, Region: {user.Region})");
Console.WriteLine($" premium-feature: {premiumFeature}");
Console.WriteLine($" rate-limit: {rateLimit}");
Console.WriteLine($" welcome-message: {welcomeMessage}");
Console.WriteLine();
}
Console.WriteLine(new string('-', 60));
Console.WriteLine("\nContext Merging Demo:");
Console.WriteLine("Default context: app_version=2.0.0, platform=console");
Console.WriteLine("When you call Get() with additional context, it's merged.");
Console.WriteLine("Per-call context overrides default context for same keys.");
// Example of context merging
var partialContext = new ReplaneContext
{
["user_id"] = "demo-user"
// platform will come from default context
};
Console.WriteLine($"\nWith partial context (user_id=demo-user):");
Console.WriteLine($" The merged context has: user_id, app_version, platform");