# .NET quickstart

Use the OpenFeature OFREP provider in a server-side .NET application. Run this command in a .NET 8 console project.

```sh
dotnet add package OpenFeature.Providers.Ofrep --version 0.1.7
```

Set `DIPSWITCH_SERVER_KEY` in the service environment. Set `DIPSWITCH_EDGE_URL` to your local edge address when self-hosting. Save this as `Program.cs`. The first argument selects a user and the second selects a flag. In a service, register the provider once at startup.

```csharp
using OpenFeature;
using OpenFeature.Model;
using OpenFeature.Providers.Ofrep;
using OpenFeature.Providers.Ofrep.Configuration;

var edge = Environment.GetEnvironmentVariable("DIPSWITCH_EDGE_URL") ?? "https://edge.dipswitch.co";
var key = Environment.GetEnvironmentVariable("DIPSWITCH_SERVER_KEY")
    ?? throw new InvalidOperationException("Set DIPSWITCH_SERVER_KEY.");
var options = new OfrepOptions(edge) { Headers = new Dictionary<string, string>() { ["X-API-Key"] = key } };
await Api.Instance.SetProviderAsync(new OfrepProvider(options));

var user = EvaluationContext.Builder().SetTargetingKey(args.ElementAtOrDefault(0) ?? "user-42").Build();
var flag = args.ElementAtOrDefault(1) ?? "new-checkout";
var result = await Api.Instance.GetClient().GetBooleanDetailsAsync(flag, false, user);
Console.WriteLine($"{result.Value.ToString().ToLowerInvariant()} {result.Reason}");
```

Each check asks edge over HTTP. Choose the fallback boolean for your feature. On an evaluation failure the client returns that fallback with an error reason.
