Skip to main content

.NET SDK API Reference

Complete API documentation for the .NET SDK.

ReplaneClient

Creates a new Replane client.

await using var replane = new ReplaneClient();

await replane.ConnectAsync(new ConnectOptions
{
BaseUrl = "https://replane.example.com",
SdkKey = "your-sdk-key"
});

ReplaneClientOptions

Options passed to the constructor. Connection options are provided via ConnectAsync.

OptionTypeDefaultDescription
ContextReplaneContextnullDefault context for evaluations
DefaultsDictionary<string, object?>nullDefault values
RequiredIReadOnlyList<string>nullRequired config names
HttpClientHttpClientnullCustom HttpClient
DebugboolfalseEnable debug logging
LoggerIReplaneLoggernullCustom logger implementation

ConnectAsync

Connects to the Replane server. Requires ConnectOptions with connection parameters.

await replane.ConnectAsync(new ConnectOptions
{
BaseUrl = "https://replane.example.com",
SdkKey = "your-sdk-key"
});

ConnectOptions

OptionTypeDefaultDescription
BaseUrlstringrequiredReplane server URL
SdkKeystringrequiredSDK key for authentication
RequestTimeoutMsint2000HTTP request timeout
ConnectionTimeoutMsint5000Initial connection timeout
RetryDelayMsint200Initial retry delay
InactivityTimeoutMsint30000SSE inactivity timeout
AgentstringnullAgent identifier

Get<T>

Gets a typed config value.

// Basic usage
var enabled = replane.Get<bool>("feature-enabled");
var limit = replane.Get<int>("rate-limit");
var apiKey = replane.Get<string>("api-key");

// With default value
var timeout = replane.Get<int>("timeout-ms", defaultValue: 5000);

Complex types

Configs can store complex objects:

// Define your config type
public record ThemeConfig
{
public bool DarkMode { get; init; }
public string PrimaryColor { get; init; } = "";
public int FontSize { get; init; }
}

public record FeatureFlags
{
public bool NewUI { get; init; }
public List<string> EnabledModules { get; init; } = [];
}

// Get complex configs
var theme = replane.Get<ThemeConfig>("theme");
var features = replane.Get<FeatureFlags>("features");

Console.WriteLine($"Dark mode: {theme.DarkMode}");
Console.WriteLine($"Enabled modules: {string.Join(", ", features.EnabledModules)}");

Get with context

Pass context for override evaluation:

var context = new ReplaneContext
{
["user_id"] = "user-123",
["plan"] = "premium",
["region"] = "us-east"
};

var premiumFeature = replane.Get<bool>("premium-feature", context);

Default context

Set default context applied to all evaluations:

var replane = new ReplaneClient(new ReplaneClientOptions
{
Context = new ReplaneContext
{
["app_version"] = "2.0.0",
["platform"] = "ios"
}
});

await replane.ConnectAsync(new ConnectOptions
{
BaseUrl = "https://replane.example.com",
SdkKey = "your-sdk-key"
});

ConfigChanged event

Subscribe to config changes:

// Subscribe to all config changes
replane.ConfigChanged += (sender, e) =>
{
Console.WriteLine($"Config '{e.ConfigName}' updated");
};

// Get typed value from the event
replane.ConfigChanged += (sender, e) =>
{
if (e.ConfigName == "feature-flag")
{
var enabled = e.GetValue<bool>();
Console.WriteLine($"Feature flag changed to: {enabled}");
}
};

// Works with complex types too
replane.ConfigChanged += (sender, e) =>
{
if (e.ConfigName == "theme")
{
var theme = e.GetValue<ThemeConfig>();
Console.WriteLine($"Theme updated: dark={theme?.DarkMode}");
}
};

// Unsubscribe when needed
void OnConfigChanged(object? sender, ConfigChangedEventArgs e)
{
Console.WriteLine($"Config changed: {e.ConfigName}");
}

replane.ConfigChanged += OnConfigChanged;
// Later...
replane.ConfigChanged -= OnConfigChanged;

Exceptions

try
{
await replane.ConnectAsync();
var value = replane.Get<string>("my-config");
}
catch (AuthenticationException)
{
// Invalid SDK key
}
catch (ConfigNotFoundException ex)
{
// Config doesn't exist
Console.WriteLine($"Config not found: {ex.ConfigName}");
}
catch (ReplaneTimeoutException ex)
{
// Operation timed out
Console.WriteLine($"Timeout after {ex.TimeoutMs}ms");
}
catch (ReplaneException ex)
{
// Other errors
Console.WriteLine($"Error [{ex.Code}]: {ex.Message}");
}

Condition operators

The SDK supports these override operators:

OperatorDescription
equalsExact match
inValue is in list
not_inValue is not in list
less_thanLess than comparison
less_than_or_equalLess than or equal
greater_thanGreater than comparison
greater_than_or_equalGreater than or equal
segmentationPercentage-based bucketing
andAll conditions must match
orAny condition must match
notNegate a condition