Coder Social home page Coder Social logo

configcat / .net-sdk Goto Github PK

View Code? Open in Web Editor NEW
27.0 6.0 8.0 1.53 MB

ConfigCat SDK for .NET. ConfigCat is a hosted feature flag service: https://configcat.com. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.

Home Page: https://configcat.com/docs/sdk-reference/csharp

License: Other

C# 99.92% PowerShell 0.04% Batchfile 0.04%
configcat feature-flags feature-toggles netstandard dotnet dotnetcore featureflags feature-flag feature-toggle remote-config

.net-sdk's Introduction

ConfigCat SDK for .NET

Supported runtimes:

  • .NET 5+
  • .NET Framework 4.5+
  • Other runtimes which implement .NET Standard 2.0+ like .NET Core 2.0+, Xamarin.Android 8.0+, Xamarin.iOS 10.14+, etc. (For more details, please refer to this table.)

https://configcat.com

ConfigCat SDK for .NET provides easy integration for your application to ConfigCat.

ConfigCat is a feature flag and configuration management service that lets you separate releases from deployments. You can turn your features ON/OFF using ConfigCat Dashboard even after they are deployed. ConfigCat lets you target specific groups of users based on region, email or any other custom user attribute.

ConfigCat is a hosted feature flag service. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.

Build status NuGet Version Sonar Coverage Quality Gate Status License: MIT

Getting Started

1. Install the package with NuGet

Install-Package ConfigCat.Client

or

dotnet add package ConfigCat.Client

2. Import ConfigCat.Client to your application

using ConfigCat.Client;

3. Go to the ConfigCat Dashboard to get your SDK Key:

SDK-KEY

4. Create a ConfigCat client instance:

var client = ConfigCatClient.Get("#YOUR-SDK-KEY#");

You can acquire singleton client instances for your SDK keys using the ConfigCatClient.Get(sdkKey: <sdkKey>) static factory method. (However, please keep in mind that subsequent calls to ConfigCatClient.Get() with the same SDK Key return a shared client instance, which was set up by the first call.)

5. Get your setting value:

var isMyAwesomeFeatureEnabled = client.GetValue("isMyAwesomeFeatureEnabled", false);

if(isMyAwesomeFeatureEnabled)
{
    doTheNewThing();
}
else
{
    doTheOldThing();
}

6. On application exit:

client.Dispose();

To ensure graceful shutdown of the client you should invoke .Dispose() method. (Client implements IDisposable interface.) Alternatively, you can also close all open clients at once using the ConfigCatClient.DisposeAll() method.

Getting user specific setting values with Targeting

Using this feature, you will be able to get different setting values for different users in your application by passing a User Object to the GetValue() function.

Read more about Targeting here.

User currentUser = new User("435170f4-8a8b-4b67-a723-505ac7cdea92");

var isMyAwesomeFeatureEnabled = client.GetValue(
	"isMyAwesomeFeatureEnabled",
	defaultValue: false,
	user: currentUser);

Sample/Demo apps

Polling Modes

The ConfigCat SDK supports 3 different polling mechanisms to acquire the setting values from ConfigCat. After latest setting values are downloaded, they are stored in the internal cache then all requests are served from there. Read more about Polling Modes and how to use them at ConfigCat Docs.

Need help?

https://configcat.com/support

Contributing

Contributions are welcome. For more info please read the Contribution Guideline.

About ConfigCat

.net-sdk's People

Contributors

adams85 avatar benonside avatar configcat-developer avatar david-zoltan avatar dependabot[bot] avatar endret avatar kp-cat avatar lajos88 avatar laliconfigcat avatar mr-sige avatar sigewuzhere avatar z4kn4fein avatar zoltan-david avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

.net-sdk's Issues

Requesting removal of Newtonsoft.Json

Is your feature request related to a problem?

Yes and no ๐Ÿ™ƒ

Describe the solution you'd like

I'd like to see the dependency to Newtonsoft.Json removed in favor of System.Text.Json and perhaps a compiled version targeting dotnet 6, to get full benefits of the latest framework version.

Additional context

Newtonsoft.Json is extremely slow compared to modern json libraries, It's also nice if we can get a smaller list of dependencies into our solution. Considering the launch of dotnet5 last year, Newtonsoft is no longer the go-to solution for handling json in dotnet, unless there is a feature gap that is too hard to re-implement with System.Text.Json.

Deadlock risk due to GetAwaiter().GetResult()

See

var config = this.configService.GetConfigAsync().GetAwaiter().GetResult();

... and it also seems completely unnecessary in the auto polling mode.

In auto polling mode, with in memory cache, you would expect the cache to be a lazy instance of a typed config (see issue #22). This would make the client in essence synchronous (with non-blocking IO in the background while polling).

Now, due to the general pattern (everything async), the synchronous GetValue method can't follow the async-all-the-way pattern and presents a risk to any applications using the client.

ConfigCat.Client makes a lot of requests

Hi,

We use ConfigCat.Client Version 2.2.1.
We notice a lot of calls happening within the same operation.
Most of them (1153) return with a HTTP statuscode 304 Not Modified and some (289) return with a 200 OK.
Still we would not expect this many calls within the same operation.
How could we provide you with more information to help debug this issue?

Improper use of Task .Result when making async methods sync

Hi!
We've ran into issues with our ThreadPool that was caused by the non async methods on the IConfigCatClient interface called too often in our application. Below are references to the lines in the client that calls .Result and needs to be refactored.
The use of .Result on an async method is very dangerous and produces deadlocks. It should be refactored to either .GetAwaiter().GetResult() or or something like this snippet, from some years ago, (microsofts entity framework team used this to get async methods run sync).

public static class AsyncUtility
{
private static readonly TaskFactory _myTaskFactory = new TaskFactory(
	CancellationToken.None,
	TaskCreationOptions.None,
	TaskContinuationOptions.None,
	TaskScheduler.Default);

public static TResult RunSync<TResult>(Func<Task<TResult>> func)
{
	return _myTaskFactory
			.StartNew<Task<TResult>>(func)
			.Unwrap<TResult>()
			.GetAwaiter()
			.GetResult();
}

public static void RunSync(Func<Task> func)
{
	_myTaskFactory
			.StartNew<Task>(func)
			.Unwrap()
			.GetAwaiter()
			.GetResult();
}
}

var c = this.configService.GetConfigAsync().Result;

return this.GetAllKeysAsync().Result;

var c = this.configService.GetConfigAsync().Result;

var c = this.configService.GetConfigAsync().Result;

json deserialization invoked too many times

Hi,
One of our use cases is getting all enabled features for user. During development we've noticed that every method ConfigCatClient class is directly or indirectly deserializing settings json file, which is causing some performance issues. Was this intended behavior or do you think it could be changed that deserialization happens once after file is refreshed.

Replace IConfigCatLogger with Microsoft.Extensions.Logging.ILogger

Is your feature request related to a problem? Please describe.

Minor inconvenience of having to author an adapter between IConfigCatLogger and Microsoft.Extensions.Logging.ILogger

Describe the solution you'd like

Be able to inject an Microsoft.Extensions.Logging.ILogger into ConfigCatClient factory method.

Describe alternatives you've considered

N/A

Additional context

N/A

New Release with LoggerWrapper fix #39

Is your feature request related to a problem? Please describe.

We set logger level = Error, but we still get some Debug output.
Screenshot 2022-09-06 at 12 30 45

I deep dived into the decompiled code and saw the issue, however when checking out the code i saw that the issue already has been solved via #39

Describe the solution you'd like

A new release of the .net-sdk with the logger wrapper fix, i guess this just was overlooked or perhaps you have some release cycle that you are following.

Describe alternatives you've considered

Just wait for a new release with the fix ๐Ÿ™๐Ÿฝ
Thanks in advance ๐Ÿ‘‹๐Ÿฝ

Provide change notifications in the .Net client

We use ConfigCat for feature flags and for dynamic configuration in general. Most values are consulted on a per-request basis, but some configuration values apply to the entire host process (e.g. a minimum thread count for the thread pool).

Since these values are not evaluated per request, it would be nice to subscribe to change notifications for these values.

Describe the solution you'd like

We're using ConfigCat in auto polling mode. The client could look for changes in the config every time it receives a new config and raise a .Net event for every changed value.

Is string.Empty a valid argument for the User constructor?

What are valid values for the identifier argument in the User constructor? Specifically, is string.Empty valid, or will this result in unexpected behavior? I partly ask because the Java SDK appears to throw an exception when passing "" whereas this .NET SDK does not.

Also, would you consider making a parameterless constructor for User? Our use case is such that we only care about evaluating rules based on custom attributes, not user ids.

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.