> ## Documentation Index
> Fetch the complete documentation index at: https://docs.westyx.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# .NET SDK - Wiring the packages together

> One call that serves IConfiguration and the container from a single Nexus client.

*Package: `WestyxNexus.Extensions.Configuration` (v0.13.0+)*

The SDK's packages compose, and one call wires them. `builder.AddWestyxNexus(config)` creates a
single `NexusClient`, serves `IConfiguration` from it, and registers it in the container - so config
binding, [secrets binding](/sdks/dotnet/secrets-binding),
[feature management](/sdks/dotnet/feature-management) and an injected client all read one cache,
behind one sync loop and one SSE connection.

```csharp theme={null}
var builder = WebApplication.CreateBuilder(args);

builder.AddWestyxNexus(new NexusConfig
{
    BaseUrl = builder.Configuration["Nexus:BaseUrl"]!,
    ApiKey  = builder.Configuration["Nexus:ApiKey"]!,
});

builder.Services.Configure<MyOptions>(builder.Configuration.GetSection("MyOptions"));
builder.Services.AddWestyxNexusSecrets<MyOptions>("MyOptions");
builder.Services.AddWestyxNexusFeatureManagement();
```

One class can take a config value and a secret at the same time. `Configure<T>(section)` fills the
properties backed by Nexus configs, `AddWestyxNexusSecrets<T>(prefix)` fills the ones backed by
secrets, and each writes only what it matched:

```csharp theme={null}
public sealed class MyOptions
{
    public string TestConfig { get; set; } = "";   // Nexus config "MyOptions.TestConfig"
    public string TestSecret { get; set; } = "";   // Nexus secret "MyOptions.TestSecret"
}
```

The client is disposed with the host.

## Which entry point to use

| You want                                                                    | Call                                                                               |
| --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| Nexus configs in `IConfiguration`, and anything else as well                | `builder.AddWestyxNexus(config)`                                                   |
| Nexus configs in `IConfiguration`, nothing else                             | [`builder.Configuration.AddWestyx(config)`](/sdks/dotnet/aspnetcore-configuration) |
| Secrets, flags or the client injected - no Nexus values in `IConfiguration` | [`builder.Services.AddWestyxNexus(...)`](/sdks/dotnet/dependency-injection)        |

`builder.Configuration.AddWestyx(config)` serves `IConfiguration` only: the client it creates stays
inside the configuration provider, and the container never sees it - which is why
`AddWestyxNexusSecrets<T>()` and `AddWestyxNexusFeatureManagement()` cannot be added next to it on
their own. `services.AddWestyxNexus(...)` is the mirror image: it serves the container only.

<Warning>
  Calling both wires **two independent clients** - two initial syncs, two TTL poll loops and two SSE
  connections, so one application consumes two of the service's connection slots.
  `builder.AddWestyxNexus(config)` exists to avoid exactly that, and rejects a second client
  registration rather than silently choosing one.
</Warning>

## What the one-call path gives up

The configuration provider needs Nexus data while `IConfiguration` is being built, which is before a
service provider exists. The client is therefore created there, with a blocking initial sync - the
same thing `builder.Configuration.AddWestyx(config)` has always done. Two consequences follow:

* **`IHttpClientFactory` is not used.** The client owns its own `HttpClient`, so handler rotation and
  any `AddHttpClient` policies do not apply to it. `NexusConfig.PooledConnectionLifetime`
  (default 2 minutes) is what keeps its DNS observations fresh.
* **The application's `ILoggerFactory` is not attached automatically**, because it does not exist
  yet. Set `NexusConfig.LoggerFactory` to route SDK diagnostics.

If you do not need Nexus values in `IConfiguration`, prefer
[`services.AddWestyxNexus(...)`](/sdks/dotnet/dependency-injection): it wires `IHttpClientFactory`
and the application's logging, and its initial sync runs asynchronously during host startup.

## Parameters

```csharp theme={null}
builder.AddWestyxNexus(config, enableStream: true, includeSecrets: false);
```

| Parameter        | Default | Meaning                                                                                                                                                                                                           |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `enableStream`   | `true`  | Start the SSE live-update stream, so `IOptionsMonitor<T>` consumers and secret bindings see changes without a restart.                                                                                            |
| `includeSecrets` | `false` | Opt in to placing secrets in `IConfiguration`. Leave it false and bind secrets with [`AddWestyxNexusSecrets<T>()`](/sdks/dotnet/secrets-binding) - see [Design decisions](/sdks/dotnet/design-decisions) for why. |
