Veff.Sqlite 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Veff.Sqlite --version 2.0.1                
NuGet\Install-Package Veff.Sqlite -Version 2.0.1                
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="Veff.Sqlite" Version="2.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Veff.Sqlite --version 2.0.1                
#r "nuget: Veff.Sqlite, 2.0.1"                
#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.
// Install Veff.Sqlite as a Cake Addin
#addin nuget:?package=Veff.Sqlite&version=2.0.1

// Install Veff.Sqlite as a Cake Tool
#tool nuget:?package=Veff.Sqlite&version=2.0.1                

Veff → Very easy feature flags

Well it's easy if you use aspnet core 😃

Currently supports 3 types of feature flags. BooleanFlag, StringFlag and PercentageFlag.

  • Boolean is a simple true/false
  • String can be assigned multiple strings. Case insensitive. Could be useful for emails, auth-roles etc.
    • can be found in different versions - StringEquals, Contains, StartsWith and EndsWith.
  • Percentage set between 0-100%. Will take a Guid or int and give back true/false x% of the time. The results are repeatable,
    so i.e. a Guid will always evaluate to true for a given percentage, unless you set a new 'randomSeed' on the flag.

Nuget

nuget package Veff is the base package, without any persistence layer.
nuget package Veff.SqlServer references the Veff package, and enables using SqlServer as the db.

Additional packages will be made as needed to support other dbs. (expect Sqlite, Postgres and MySql)

Usage

Create a normal c# class or record, and add the Flags you want as normal get-only properties. Remember to 'implement' the empty marker interface IFeatureFlagContainer.

You do not have to set the Flags to anything (i.e. BooleanFlag.Empty as I do below). Only really useful for calming the roslyn analyzer if you have nullable reference types enabled.


public class EmailFeatures : IFeatureFlagContainer
{
    public BooleanFlag SendSpamMails { get; } = BooleanFlag.Empty;
    public PercentageFlag IncludeFunnyCatPictures { get; } = PercentageFlag.Empty;
    public StringEqualsFlag SendActualEmails { get; } = StringEqualsFlag.Empty;
}

Setup


var builder = WebApplication.CreateBuilder(args);

builder.Services.AddVeff(veffBuilder =>
{
    var connectionString = builder.Configuration.GetConnectionString("SqlDb")!;

    veffBuilder
        .WithSqlServer(connectionString, TimeSpan.FromSeconds(30))
        .AddFeatureFlagContainersFromAssembly() // Finds all IFeatureFlagContainer in scanned assemblies 
        .AddDashboardAuthorizersFromAssembly() // Same as above but for IVeffDashboardAuthorizers (only needed if you want to use the dashboard, and hide it behind some authorization)
        .AddExternalApiAuthorizersFromAssembly(); // Same as above but for IVeffExternalApiAuthorizers (only needed if you want to use the external api and hide it behind some auth)
});

var app = builder.Build();

app.UseVeff(s =>
{
    s.UseVeffDashboard(); // setup dashboard where you can manage and edit your feature flags. 
    s.UseVeffExternalApi(); // exposes a http api that allows external services to make use of the feature flags.
});

// Just inject your FeatureFlagContainers via normal DI
app.MapGet("/", ([FromServices] EmailFeatures ef) 
    => $"{ef.SendSpamEmails.IsEnabled}\n{ef.SendActualEmails.EnabledFor("me")}");

app.Run();

Note

The FeatureContainers does not care about the data they are initialized with, it will be overridden with whats stored in the db. This also means that flags defaults to false until otherwise specified in the dashboard.

Dashboard

// TODO
Needs to be reworked a bit 😃

External API

// TODO
Useful for exposing the feature flags to external services.

Testing

How do you test class that injects a feature container - since it is not hidden behind an interface?
Example:


    public interface IMySuperService
    {
        string DoStuff();
    }

    public class MySuperService : IMySuperService
    {
        private readonly FooBarFeatures _fooBarFeatures;

        public MySuperService(FooBarFeatures fooBarFeatures)
        {
            _fooBarFeatures = fooBarFeatures;
        }
        
        public string DoStuff()
        {
            return _fooBarFeatures.Foo.IsEnabled ? "Hello" : "goodbye";
        }
    }

Luckily you can easily test by initializing the FeatureContainer with MockedFlags


    public class MySuperServiceTest
    {
        private readonly MySuperService _sut;

        public MySuperServiceTest()
        {
            var fooBarFeatures = new FooBarFeatures
            {
                Foo = new MockedBooleanFlag(true),
                Baz = new MockedStringFlag("my@email.com")
            };

            _sut = new MySuperService(fooBarFeatures);
        }
        
        [Fact]
        public void Test1()
        {
            var doStuff = _sut.DoStuff();
            Assert.Equal("Hello", doStuff);
        }
    }


Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 was computed.  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. 
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
2.0.3 354 3/21/2023
2.0.2 198 3/21/2023
2.0.1 199 3/21/2023