{"id":19935052,"url":"https://github.com/optimizely/csharp-sdk","last_synced_at":"2025-05-03T12:31:00.350Z","repository":{"id":20606935,"uuid":"87469917","full_name":"optimizely/csharp-sdk","owner":"optimizely","description":".NET based C# SDK for Optimizely Feature Experimentation and Optimizely Full Stack (legacy).","archived":false,"fork":false,"pushed_at":"2025-03-05T21:02:28.000Z","size":6322,"stargazers_count":19,"open_issues_count":1,"forks_count":20,"subscribers_count":96,"default_branch":"master","last_synced_at":"2025-04-29T16:21:45.622Z","etag":null,"topics":["optimizely-environment-prod","optimizely-environment-public","optimizely-owner-px"],"latest_commit_sha":null,"homepage":"https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/csharp-sdk","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/optimizely.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-06T20:03:05.000Z","updated_at":"2025-04-21T20:12:34.000Z","dependencies_parsed_at":"2023-11-22T16:24:08.579Z","dependency_job_id":"57b58806-4013-4a6b-beb9-323ab83d79a6","html_url":"https://github.com/optimizely/csharp-sdk","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Fcsharp-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Fcsharp-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Fcsharp-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Fcsharp-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/optimizely","download_url":"https://codeload.github.com/optimizely/csharp-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252190652,"owners_count":21708916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["optimizely-environment-prod","optimizely-environment-public","optimizely-owner-px"],"created_at":"2024-11-12T23:18:38.849Z","updated_at":"2025-05-03T12:31:00.335Z","avatar_url":"https://github.com/optimizely.png","language":"C#","readme":"# Optimizely C# SDK\n![Semantic](https://img.shields.io/badge/sem-ver-lightgrey.svg?style=plastic)\n![CI](https://github.com/optimizely/csharp-sdk/actions/workflows/csharp.yml/badge.svg?branch=master)\n[![NuGet](https://img.shields.io/nuget/v/Optimizely.SDK.svg?style=plastic)](https://www.nuget.org/packages/Optimizely.SDK/)\n[![Apache 2.0](https://img.shields.io/github/license/nebula-plugins/gradle-extra-configurations-plugin.svg)](http://www.apache.org/licenses/LICENSE-2.0)\n\nThis repository houses the .Net based C# SDK for use with Optimizely Feature Experimentation and Optimizely Full Stack (legacy).\n\nOptimizely Feature Experimentation is an A/B testing and feature management tool for product development teams, letting you experiment at every step. Using Optimizely Feature Experimentation allows for every feature on your roadmap to be an opportunity to discover hidden insights. Learn more at [Optimizely.com](https://www.optimizely.com/products/experiment/feature-experimentation/), or see the [developer documentation](https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/welcome).\n\nOptimizely Rollouts is [free feature flags](https://www.optimizely.com/free-feature-flagging/) for development teams. You can easily roll out and roll back features in any application without code deploys, mitigating risk for every feature on your roadmap.\n\n\n## Get Started\n\nRefer to the [C# SDK's developer documentation](https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/csharp-sdk) for detailed instructions on getting started with using the SDK.\n\n### Install the C# SDK\n\nThe SDK can be installed through [NuGet](https://www.nuget.org):\n\n```\nPM\u003e Install-Package Optimizely.SDK\n```\n\nAn ASP.Net MVC sample project demonstrating how to use the SDK is available as well:\n\n```\nPM\u003e Install-Package Optimizely.SDK.Sample\n```\n\nSimply compile and run the Sample application to see it in use.\nNote that the way the Demo App stores data in memory is not recommended for production use\nand is merely illustrates how to use the SDK.\n\n\n### Feature Management Access\n\nTo access the Feature Management configuration in the Optimizely dashboard, please contact your Optimizely customer success manager.\n\n## Use the C# SDK\n\nSee the Optimizely Feature Experimentation [developer documentation](https://docs.developers.optimizely.com/experimentation/v4.0-full-stack/docs/csharp-sdk) to learn how to set up your first C# project and use the SDK.\n\n### Initialization\n\nCreate the Optimizely Client, for example:\n\n```\nprivate static Optimizely Optimizely =\n    new Optimizely(\n        datafile: myProjectConfig,\n        eventDispatcher: myEventDispatcher,\n        logger: myLogger,\n        errorHandler: myErrorHandler,\n        skipJsonValidation: false);\n```\n\nSince this class parses the Project Config file, you should not create this per request.\n\n#### APIs\n\nThis class exposes three main calls:\n1. Activate\n2. Track\n3. GetVariation\n\nActivate and Track are used in the demonstration app.  See the Optimizely documentation regarding how to use these.\n\n#### Plug-in Interfaces\n\nThe Optimizely client object accepts the following plug-ins:\n1. `IEventDispatcher` handles the HTTP requests to Optimizely.  The default implementation is an asynchronous \"fire and forget\".\n2. `ILogger` exposes a single method, Log, to record activity in the SDK.  An example of a class to bridge the SDK's Log to Log4Net is provided in the Demo Application.\n3. `IErrorHandler` allows you to implement custom logic when Exceptions are thrown.  Note that Exception information is already included in the Log.\n4. `ProjectConfigManager` exposes method for retrieving ProjectConfig instance. Examples include `FallbackProjectConfigManager` and `HttpProjectConfigManager`.\n5. `EventProcessor` provides an intermediary processing stage within event production. It's assumed that the EventProcessor dispatches events via a provided EventDispatcher. Examples include `ForwardingEventProcessor` and `BatchEventProcessor`.\nThese are optional plug-ins and default behavior is implement if none are provided.\n\n#### OptimizelyFactory\n\n[`OptimizelyFactory`](https://github.com/optimizely/csharp-sdk/blob/master/OptimizelySDK/OptimizelyFactory.cs)\nprovides basic utility to instantiate the Optimizely SDK with a minimal number of configuration options.\n\n`OptimizelyFactory` does not capture all configuration and initialization options. For more use cases,\nbuild the resources via their respective builder classes.\n\n##### Use OptimizelyFactory\n\nYou must provide the SDK key at runtime, either directly via the factory method:\n```\nOptimizely optimizely = OptimizelyFactory.newDefaultInstance(\u003c\u003cSDK_KEY\u003e\u003e);\n```\n\nYou can also provide default datafile with the SDK key.\n```\nOptimizely optimizely = OptimizelyFactory.newDefaultInstance(\u003c\u003cSDK_KEY\u003e\u003e, \u003c\u003cFallback\u003e\u003e);\n```\n##### Using App.config in OptimizelyFactory\n\nOptimizelyFactory provides support of setting configuration variables in App.config:\nUser can provide variables using following procedure:\n1. In App.config file of your project in **\u003cconfiguration\u003e** add following:\n```\n\u003cconfigSections\u003e\n    \u003csection name=\"optlySDKConfigSection\"\n             type=\"OptimizelySDK.OptimizelySDKConfigSection, OptimizelySDK, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null\" /\u003e\n  \u003c/configSections\u003e\n```\n2. Now add **optlySDKConfigSection** below **\u003cconfigSections\u003e**. In this section you can add and set following **HttpProjectConfigManager** and **BatchEventProcessor** variables: \n```\n\u003coptlySDKConfigSection\u003e\n  \n    \u003cHttpProjectConfig sdkKey=\"43214321\" \n                       url=\"www.testurl.com\" \n                       format=\"https://cdn.optimizely.com/data/{0}.json\" \n                       pollingInterval=\"2000\" \n                       blockingTimeOutPeriod=\"10000\" \n                       datafileAccessToken=\"testingtoken123\"\n                       autoUpdate=\"true\" \n                       defaultStart=\"true\"\u003e\n    \u003c/HttpProjectConfig\u003e\n\n    \u003cBatchEventProcessor batchSize=\"10\"\n                         flushInterval=\"2000\"\n                         timeoutInterval=\"10000\"\n                         defaultStart=\"true\"\u003e\n    \u003c/BatchEventProcessor\u003e\n  \n  \u003c/optlySDKConfigSection\u003e\n```\n3. After setting these variables you can instantiate the Optimizely SDK using function:\n```\nOptimizely optimizely = OptimizelyFactory.newDefaultInstance();\n```\n\n#### BatchEventProcessor\n[BatchEventProcessor](https://github.com/optimizely/csharp-sdk/blob/master/OptimizelySDK/Event/BatchEventProcessor.cs) is a batched implementation of the [EventProcessor](https://github.com/optimizely/csharp-sdk/blob/master/OptimizelySDK/Event/EventProcessor.cs)\n     * Events passed to the BatchEventProcessor are immediately added to a BlockingQueue.\n     * The BatchEventProcessor maintains a single consumer thread that pulls events off of the BlockingQueue and buffers them for either a configured batch size or for a maximum duration before the resulting LogEvent is sent to the NotificationManager.\n##### Use BatchEventProcessor\n\n```\nEventProcessor eventProcessor = new BatchEventProcessor.Builder()\n                .WithMaxBatchSize(MaxEventBatchSize)\n                .WithFlushInterval(MaxEventFlushInterval)\n                .WithEventDispatcher(eventDispatcher)\n                .WithNotificationCenter(notificationCenter)\n                .Build();\n```\n\n##### Max Event Batch Size\n\nThe Max event batch size is used to limit eventQueue batch size and events will be dispatched when limit reaches.\n\n##### Flush Interval\n\nThe FlushInterval is used to specify a delay between consecutive flush events call. Event batch will be dispatched after meeting this specified timeSpan.\n\n##### Event Dispatcher \n\nCustom EventDispatcher can be passed.\n\n##### Notification Center\n\nCustom NotificationCenter can be passed. \n\n#### HttpProjectConfigManager\n\n[`HttpProjectConfigManager`](https://github.com/optimizely/csharp-sdk/blob/master/OptimizelySDK/Config/HttpProjectConfigManager.cs)\nis an implementation of the abstract [`PollingProjectConfigManager`](https://github.com/optimizely/csharp-sdk/blob/master/OptimizelySDK/Config/PollingProjectConfigManager.cs).\nThe `Poll` method is extended and makes an HTTP GET request to the configured URL to asynchronously download the\nproject datafile and initialize an instance of the ProjectConfig.\n\nBy default, `HttpProjectConfigManager` will block until the first successful datafile retrieval, up to a configurable timeout.\nSet the frequency of the polling method and the blocking timeout with `HttpProjectConfigManager.Builder`.\n\n##### Use HttpProjectConfigManager\n\n```\nHttpProjectConfigManager httpManager = new HttpProjectConfigManager.Builder()\n\t.WithSdkKey(sdkKey)\n\t.WithPollingInterval(TimeSpan.FromMinutes(1))\n\t.Build();\n```\n\n##### SDK key\n\nThe SDK key is used to compose the outbound HTTP request to the default datafile location on the Optimizely CDN.\n\n##### Polling interval\n\nThe polling interval is used to specify a fixed delay between consecutive HTTP requests for the datafile. Between 1 to 4294967294 miliseconds is valid duration. Otherwise default 5 minutes will be used.\n\n##### Blocking Timeout Period\n\nThe blocking timeout period is used to specify a maximum time to wait for initial bootstrapping. Between 1 to 4294967294 miliseconds is valid blocking timeout period. Otherwise default value 15 seconds will be used.\n\n##### Initial datafile\n\nYou can provide an initial datafile via the builder to bootstrap the `ProjectConfigManager` so that it can be used immediately without blocking execution.\n\n##### URL\n\nThe URL is used to specify the location of datafile.\n\n##### Format\n\nThis option enables user to provide a custom URL format to fetch the datafile.\n\n##### Start by default\n\nThis option is used to specify whether to start the config manager on initialization or not. If no value is provided, by default it is true and will start polling datafile from remote immediately.\n\n##### Datafile access token\n\nThis option is used to provide token for datafile belonging to a secure environment.\n\n## SDK Development\n\n### Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md).\n\n### Third Party Licenses\n\nOptimizely SDK uses third party software:\n[murmurhash-signed](https://www.nuget.org/packages/murmurhash-signed/),\n[Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json/), and\n[NJsonSchema](https://www.nuget.org/packages/NJsonSchema/).\n\n### Other Optimzely SDKs\n\n- Agent - https://github.com/optimizely/agent\n\n- Android - https://github.com/optimizely/android-sdk\n\n- Flutter - https://github.com/optimizely/optimizely-flutter-sdk\n\n- Go - https://github.com/optimizely/go-sdk\n\n- Java - https://github.com/optimizely/java-sdk\n\n- JavaScript - https://github.com/optimizely/javascript-sdk\n\n- PHP - https://github.com/optimizely/php-sdk\n\n- Python - https://github.com/optimizely/python-sdk\n\n- React - https://github.com/optimizely/react-sdk\n\n- Ruby - https://github.com/optimizely/ruby-sdk\n\n- Swift - https://github.com/optimizely/swift-sdk\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foptimizely%2Fcsharp-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foptimizely%2Fcsharp-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foptimizely%2Fcsharp-sdk/lists"}