FlexiToggle.Sdk 1.0.0

dotnet add package FlexiToggle.Sdk --version 1.0.0
                    
NuGet\Install-Package FlexiToggle.Sdk -Version 1.0.0
                    
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="FlexiToggle.Sdk" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FlexiToggle.Sdk" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="FlexiToggle.Sdk" />
                    
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 FlexiToggle.Sdk --version 1.0.0
                    
#r "nuget: FlexiToggle.Sdk, 1.0.0"
                    
#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 FlexiToggle.Sdk@1.0.0
                    
#: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=FlexiToggle.Sdk&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=FlexiToggle.Sdk&version=1.0.0
                    
Install as a Cake Tool

FlexiToggle .NET SDK

NuGet Downloads

SDK oficial do FlexiToggle para .NET - Gerencie feature flags, A/B testing e configurações dinâmicas em suas aplicações .NET.

🚀 Instalação

dotnet add package FlexiToggle.Sdk

⚡ Quick Start

1. Configuração no appsettings.json

{
  "FlexiToggle": {
    "ApiUrl": "https://api.flexitoggle.com",
    "ProjectKey": "seu-projeto-key",
    "Environment": "production",
    "ApiKey": "sua-api-key",
    "PollingInterval": "00:00:30",
    "HttpTimeout": "00:00:10"
  }
}

2. Registrar no Container de DI

using FlexiToggle.Sdk.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Adicionar FlexiToggle SDK
builder.Services.AddFlexiToggle(builder.Configuration);

var app = builder.Build();

3. Usar em Controllers/Services

using FlexiToggle.Sdk;

[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
    private readonly IFlexiToggleClient _flexiToggle;

    public ProductsController(IFlexiToggleClient flexiToggle)
    {
        _flexiToggle = flexiToggle;
    }

    [HttpGet]
    public async Task<IActionResult> GetProducts()
    {
        // Feature Flag Booleana
        if (await _flexiToggle.IsEnabledAsync("new-product-layout"))
        {
            return Ok(await GetNewProductLayout());
        }

        // Configuração Dinâmica
        var maxProducts = await _flexiToggle.GetNumberAsync("max-products-per-page", 10);
        var products = await GetProducts(maxProducts);

        return Ok(products);
    }
}

📖 Métodos Disponíveis

Feature Flags Booleanas

// Verificar se uma flag está ativa
bool isEnabled = await client.IsEnabledAsync("feature-name");

// Com valor padrão
bool isEnabled = await client.IsEnabledAsync("feature-name", defaultValue: false);

// Com contexto de usuário
var context = new { UserId = 123, Email = "user@example.com" };
bool isEnabled = await client.IsEnabledAsync("feature-name", context);

Configurações Dinâmicas

// String
string value = await client.GetStringAsync("config-name", "default-value");

// Número
double number = await client.GetNumberAsync("max-items", 10);

// JSON/Objeto
var config = await client.GetJsonAsync<MyConfig>("complex-config");

Eventos e Analytics

// Registrar evento customizado
await client.TrackEventAsync("button-clicked", new 
{ 
    ButtonId = "checkout",
    UserId = 123 
});

// Registrar conversão
await client.TrackConversionAsync("purchase-completed", new 
{ 
    Amount = 99.99,
    ProductId = "prod-123" 
});

🔧 Configuração Avançada

Configuração por Código

builder.Services.AddFlexiToggle(config =>
{
    config.ApiUrl = "https://api.flexitoggle.com";
    config.ProjectKey = "meu-projeto";
    config.Environment = "production";
    config.ApiKey = "minha-api-key";
    config.PollingInterval = TimeSpan.FromSeconds(30);
    config.HttpTimeout = TimeSpan.FromSeconds(10);
});

Configuração com HttpClient Customizado

builder.Services.AddHttpClient<IFlexiToggleClient, FlexiToggleClient>(client =>
{
    client.BaseAddress = new Uri("https://api.flexitoggle.com");
    client.Timeout = TimeSpan.FromSeconds(30);
    client.DefaultRequestHeaders.Add("User-Agent", "MeuApp/1.0");
});

Cache e Performance

builder.Services.AddFlexiToggle(config =>
{
    config.ApiUrl = "https://api.flexitoggle.com";
    config.ProjectKey = "meu-projeto";
    config.Environment = "production";
    config.ApiKey = "minha-api-key";
    
    // Configurações de performance
    config.PollingInterval = TimeSpan.FromMinutes(1); // Polling a cada minuto
    config.CacheTimeout = TimeSpan.FromMinutes(5);    // Cache por 5 minutos
    config.EnableAnalytics = true;                    // Habilitar analytics
    config.AnalyticsBufferSize = 100;                 // Buffer de 100 eventos
});

🎯 Targeting e Contexto

Contexto de Usuário

var userContext = new Dictionary<string, object>
{
    ["userId"] = 123,
    ["email"] = "user@example.com",
    ["plan"] = "premium",
    ["country"] = "BR",
    ["age"] = 25
};

bool isEnabled = await client.IsEnabledAsync("premium-feature", userContext);

Contexto de Sessão

var sessionContext = new Dictionary<string, object>
{
    ["sessionId"] = Guid.NewGuid().ToString(),
    ["userAgent"] = Request.Headers["User-Agent"].ToString(),
    ["ipAddress"] = HttpContext.Connection.RemoteIpAddress?.ToString(),
    ["referrer"] = Request.Headers["Referer"].ToString()
};

string variant = await client.GetStringAsync("ab-test-variant", "control", sessionContext);

🧪 A/B Testing

// Obter variante do teste A/B
string variant = await client.GetStringAsync("checkout-button-color", "blue");

switch (variant)
{
    case "red":
        return RedCheckoutButton();
    case "green":
        return GreenCheckoutButton();
    default:
        return BlueCheckoutButton();
}

// Registrar conversão para o teste
await client.TrackConversionAsync("checkout-completed", new 
{ 
    Variant = variant,
    Amount = orderTotal 
});

📊 Monitoramento e Logs

Logs Estruturados

builder.Services.AddLogging(logging =>
{
    logging.AddConsole();
    logging.SetMinimumLevel(LogLevel.Information);
});

Health Checks

builder.Services.AddHealthChecks()
    .AddCheck<FlexiToggleHealthCheck>("flexitoggle");

app.MapHealthChecks("/health");

🔒 Segurança

Configuração Segura

// Usar variáveis de ambiente para informações sensíveis
builder.Services.AddFlexiToggle(config =>
{
    config.ApiUrl = Environment.GetEnvironmentVariable("FLEXITOGGLE_API_URL");
    config.ApiKey = Environment.GetEnvironmentVariable("FLEXITOGGLE_API_KEY");
    config.ProjectKey = Environment.GetEnvironmentVariable("FLEXITOGGLE_PROJECT_KEY");
    config.Environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
});

🚀 Deploy e Produção

Configuração por Ambiente

Development:

{
  "FlexiToggle": {
    "Environment": "development",
    "PollingInterval": "00:00:10",
    "EnableAnalytics": false
  }
}

Production:

{
  "FlexiToggle": {
    "Environment": "production",
    "PollingInterval": "00:01:00",
    "EnableAnalytics": true,
    "CacheTimeout": "00:05:00"
  }
}

📝 Exemplos Completos

Veja mais exemplos na pasta examples do repositório.

🤝 Contribuição

Contribuições são bem-vindas! Veja nosso guia de contribuição.

📄 Licença

Este projeto está licenciado sob a licença MIT - veja o arquivo LICENSE para detalhes.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 was computed.  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. 
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
1.0.0 115 2/27/2026