OpenFeature.Contrib.Providers.Flagd 0.3.5

Prefix Reserved
dotnet add package OpenFeature.Contrib.Providers.Flagd --version 0.3.5
                    
NuGet\Install-Package OpenFeature.Contrib.Providers.Flagd -Version 0.3.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenFeature.Contrib.Providers.Flagd" Version="0.3.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenFeature.Contrib.Providers.Flagd" Version="0.3.5" />
                    
Directory.Packages.props
<PackageReference Include="OpenFeature.Contrib.Providers.Flagd" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenFeature.Contrib.Providers.Flagd --version 0.3.5
                    
#r "nuget: OpenFeature.Contrib.Providers.Flagd, 0.3.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OpenFeature.Contrib.Providers.Flagd@0.3.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenFeature.Contrib.Providers.Flagd&version=0.3.5
                    
Install as a Cake Addin
#tool nuget:?package=OpenFeature.Contrib.Providers.Flagd&version=0.3.5
                    
Install as a Cake Tool

flagd .NET Provider

⚠️ DEPRECATED: This package will be renamed to OpenFeature.Providers.Flagd (removing the "Contrib" suffix) in a future release. The current package name will be deprecated in favour of the new package name.

The flagd Flag provider allows you to connect to your flagd instance.

Requirements

  • open-feature/dotnet-sdk v2.0.0 > v3.0.0

Install dependencies

We will first install the OpenFeature SDK and the flagd provider.

.NET Cli

dotnet add package OpenFeature.Contrib.Providers.Flagd

Package Manager

NuGet\Install-Package OpenFeature.Contrib.Providers.Flagd

Package Reference

<PackageReference Include="OpenFeature.Contrib.Providers.Flagd" />

Packet cli

paket add OpenFeature.Contrib.Providers.Flagd

Cake

// Install OpenFeature.Contrib.Providers.Flagd as a Cake Addin
#addin nuget:?package=OpenFeature.Contrib.Providers.Flagd

// Install OpenFeature.Contrib.Providers.Flagd as a Cake Tool
#tool nuget:?package=OpenFeature.Contrib.Providers.Flagd

Using the flagd Provider with the OpenFeature SDK

This example assumes that the flagd server is running locally For example, you can start flagd with the following example configuration:

flagd start --uri https://raw.githubusercontent.com/open-feature/flagd/main/config/samples/example_flags.json

When the flagd service is running, you can use the SDK with the flagd Provider as in the following example console application:

using OpenFeature.Contrib.Providers.Flagd;

namespace OpenFeatureTestApp
{
    class Hello {
        static void Main(string[] args) {
            var flagdProvider = new FlagdProvider(new Uri("http://localhost:8013"));

            // Set the flagdProvider as the provider for the OpenFeature SDK
            OpenFeature.Api.Instance.SetProvider(flagdProvider);

            var client = OpenFeature.Api.Instance.GetClient("my-app");

            var val = client.GetBooleanValueAsync("myBoolFlag", false, null);

            // Print the value of the 'myBoolFlag' feature flag
            System.Console.WriteLine(val.Result.ToString());
        }
    }
}

Using the flagd Provider with the OpenFeature SDK and Dependency Injection

You can also use the flagd Provider with the OpenFeature SDK and Dependency Injection. The following example shows how to do this using Microsoft.Extensions.DependencyInjection:

Before you start, make sure you have the OpenFeature.Hosting NuGet package installed:

dotnet add package OpenFeature.Hosting

Or with Package Manager:

NuGet\Install-Package OpenFeature.Hosting

Now you can set up Dependency Injection with OpenFeature and the flagd Provider in your Program.cs file. When not specifying any configuration options, the flagd Provider will use the default values for the variables as described below.

using OpenFeature;
using OpenFeature.DependencyInjection.Providers.Flagd;

namespace OpenFeatureTestApp
{
    class Hello {
        static void Main(string[] args) {
            var builder = WebApplication.CreateBuilder(args);

            builder.Services.AddOpenFeature(config =>
            {
                config.AddHostedFeatureLifecycle()
                    .AddFlagdProvider();
            });

            var app = builder.Build();

            // ... ommitted for brevity
        }
    }
}

You can override the default configuration options by specifying properties on the FlagdProviderOptions on the AddFlagdProvider method.

using OpenFeature;
using OpenFeature.DependencyInjection.Providers.Flagd;

namespace OpenFeatureTestApp
{
    class Hello {
        static void Main(string[] args) {
            var builder = WebApplication.CreateBuilder(args);

            builder.Services.AddOpenFeature(config =>
            {
                config.AddHostedFeatureLifecycle()
                    .AddFlagdProvider(o =>
                    {
                        o.Host = builder.Configuration["FlagdProviderOptions:Host"];
                        o.Port = int.Parse(builder.Configuration["FlagdProviderOptions:Port"] ?? "8013");

                        // other configurations can be set here
                    });
            });

            var app = builder.Build();

            // ... ommitted for brevity
        }
    }
}

Configuring the FlagdProvider

The URI of the flagd server to which the flagd Provider connects to can either be passed directly to the constructor, or be configured using the following environment variables:

Option name Environment variable name Type Default Values
host FLAGD_HOST string localhost
port FLAGD_PORT number 8013
tls FLAGD_TLS boolean false
tls certPath FLAGD_SERVER_CERT_PATH string
unix socket path FLAGD_SOCKET_PATH string
Caching FLAGD_CACHE string lru
Maximum cache size FLAGD_MAX_CACHE_SIZE number 10
Maximum event stream retries FLAGD_MAX_EVENT_STREAM_RETRIES number 3
Resolver type FLAGD_RESOLVER string rpc rpc, in-process
Source selector FLAGD_SOURCE_SELECTOR string
Logger n/a n/a

Note that if FLAGD_SOCKET_PATH is set, this value takes precedence, and the other variables (FLAGD_HOST, FLAGD_PORT, FLAGD_TLS, FLAGD_SERVER_CERT_PATH) are disregarded.

Note that if you are on NET462 through NET48 as the target framework for your project, you are required to enable TLS and supply a certificate path as part of your configuration. This is a limitation Microsoft has documented.

If you rely on the environment variables listed above, you can use the empty constructor which then configures the provider accordingly:

var flagdProvider = new FlagdProvider();

Alternatively, if you would like to pass the URI directly, you can initialise it as follows:

// either communicate with Flagd over HTTP ...
var flagdProvider = new FlagdProvider(new Uri("http://localhost:8013"));

// ... or use the unix:// prefix if the provider should communicate via a unix socket
var unixFlagdProvider = new FlagdProvider(new Uri("unix://socket.tmp"));

In-process resolver type

The flagd provider also supports the in-process provider mode, which is activated by setting the FLAGD_RESOLVER env var to IN_PROCESS. In this mode, the provider will connect to a service implementing the flagd.sync.v1 interface and subscribe to a feature flag configuration determined by the FLAGD_SOURCE_SELECTOR. After an initial retrieval of the desired flag configuration, the in-process provider will keep the latest known state in memory, meaning that no requests need to be sent over the network for resolving flags that are part of the flag configuration. Updates to the flag configuration will be sent via the grpc event stream established between the in-process provider and the service implementing the flagd.sync.v1 interface (e.g. flagd-proxy).

Example of using the in-process provider mode:

using OpenFeature.Contrib.Providers.Flagd;

namespace OpenFeatureTestApp
{
    class Hello {
        static void Main(string[] args) {

            var flagdConfig = new FlagdConfigBuilder()
                // set the host and port for flagd-proxy
                .WithHost("localhost")
                .WithPort("8015")
                // set the resolver type to 'IN_PROCESS'
                .WithResolverType(ResolverType.IN_PROCESS)
                // provide the flag source selector, e.g. the name of a Flags custom resource which is watched by the flagd-proxy
                .WithSourceSelector("core.openfeature.dev/flags/sample-flags")
                .Build();

            var flagdProvider = new FlagdProvider(flagdConfig);

            // Set the flagdProvider as the provider for the OpenFeature SDK
            OpenFeature.Api.Instance.SetProvider(flagdProvider);

            var client = OpenFeature.Api.Instance.GetClient("my-app");

            var val = client.GetBooleanValueAsync("myBoolFlag", false, null);

            // Print the value of the 'myBoolFlag' feature flag
            System.Console.WriteLine(val.Result.ToString());
        }
    }
}

By default the in-process provider will attempt to validate the flag configurations against the Flags and targeting schemas. If validation fails a warning log will be generated. You must configure a logger using the FlagdConfigBuilder. The in-process provider uses the Microsoft.Extensions.Logging abstractions.

var logger = loggerFactory.CreateLogger<Program>();
var flagdConfig = new FlagdConfigBuilder()
    .WithLogger(logger)
    .Build();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.5 1,363 2/3/2026
0.3.4 22,427 10/17/2025
0.3.3 22,211 7/4/2025
0.3.2 27,321 4/23/2025
0.3.0 35,842 8/22/2024
0.2.3 5,070 8/21/2024
0.2.2 3,091 8/20/2024
0.2.1 18,288 7/16/2024
0.2.0 3,213 7/8/2024
0.1.9 13,373 4/30/2024
0.1.8 20,434 1/25/2024
0.1.7 5,170 9/13/2023
0.1.5 5,734 4/7/2023
0.1.4 3,568 4/4/2023
0.1.3 3,996 3/22/2023
0.1.2 3,646 2/13/2023
0.1.0 3,743 10/16/2022