Skip to content

featureflow/featureflow-dotnet-client

Repository files navigation

featureflow-dotnet-sdk

.NET client SDK for Featureflow compatible with .NET Framework 4.5, .NET Standard 1.3, .NET Standard 2.0.

Get your Featureflow account at featureflow.io

Get Started

The easiest way to get started is to follow the Featureflow quick start guides

Change Log

Please see CHANGELOG.

Installation

Using NuGet

Install-Package Featureflow

Usage

Quick start

Get your 'Server Environment Api Key' from the environment page in featureflow and instantiate a singleton client:

Instantiate the client

  var client = FeatureflowClientFactory.Create("srv-env-YOUR_SERVER_ENVIRONMENT_API_KEY");

or

  var client = await FeatureflowClientFactory.CreateAsync("srv-env-YOUR_SERVER_ENVIRONMENT_API_KEY");

Evaluate a feature

In your code, you can test the value of your feature where the value of my-feature-key is equal to 'on'

  var result = client.Evaluate("example-feature", user).Is("on");

Because the most commonly used variants for any feature are 'on' and 'off', we have provided two helper methods .IsOn() and .IsOff()

    if (client.Evaluate("example-feature").IsOn())
    {
	    //do something
    }
    if (client.Evaluate("example-feature").IsOff())
    {
	    //do something
    }    

Setting feature failover values

The feature failover value is used if the feature is not found in the features cache for any reason. The default value is 'off'. You may define your features in code and specify a failover value.

var client = new FeatureflowClient("srv-env-YOUR_KEY", new List<Feature>
		    {
			    new Feature
			    {
				    Key = "feature-one",
				    FailoverVariant = "unavailable"
			    },
			    new Feature
			    {
				    Key = "new-one",
				    FailoverVariant = "green"
			    }
		    }, new FeatureflowConfig());

Adding a User

You can pass user information in to allow features to be targeted. At the point in time of evaluation (e.g. on a rest call or other call) you can create and pass in a user by creating a FeatureflowUser object. We have a builder to help:

var user = new User("1234");
user.WithAttribute("region", "sydney");
user.WithAttribute("days", new List<int> { 11, 1, 4, 29 });
user.WithSessionAttribute("dayofweek", 5);
var result = client.Evaluate("example-feature", user).Value();

User attributes can be of type DateTime, String, any numeric type (like int or double) or IEnumerable<DateTime>, IEnumerable<String> or IEnumerable of any numeric type

When a list of user attributes is passed in, each rule may match any of the attribute values, additionally each attribute is stored in featureflow for subsequent lookup in rule creation.

If you do not want the user saved in featureflow set '.SaveUser(false)' on the FeatureflowUser object.

Evaluate by passing the user into the evaluate method:

var result = client.Evaluate("example-feature", user).Value();

Further documentation can be found here

About featureflow

Roadmap

  • Improved .NET standard compatibility
  • Polling feature stream client
  • Improve README
  • SSE feature stream client
  • Post Events Client
  • Register features on Startup
  • Optimised events summaries

License

Apache-2.0

About

Microsoft Dot Net Client for Featureflow feature control.

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages