Introduction

Flux.JSON is an implementation of Flux that uses JSON as a data source.

It's intended to be used for testing purposes, as it allows you to quickly mock external services by simply providing JSON data as a source, whether as a simple .Net string or a JSON file.

We recommend reviewing the Flux documentation first.

Installation

To use Flux.JSON in your project, add the nuget package (currently in prerelease state)

dotnet add package BitzArt.Flux.Json --prerelease

Usage

Configure Flux

You can populate Flux sets data from JSON strings:

var myJson =
"""
[
    {
        "id": 1,
        "name": "Test object 1"
    },
    {
        "id": 2,
        "name": "Test object 2"
    }
]
""";

services.AddFlux(flux =>
{
    flux.AddService("service1")     // Give your external service a specific name
        .UsingJson()                // Use Flux.JSON implementation
        .AddSet<YourModel>()        // Adds a Set for a specific model
            .FromJson(myJson);      // Set data source
});

Or from a JSON file:

var filePath = "path/to/my/file.json";

services.AddFlux(flux =>
{
    flux.AddService("service1")      // Give your external service a specific name
        .UsingJson()                 // Use Flux.JSON implementation
        .AddSet<YourModel>()         // Adds a Set for a specific model
            .FromJsonFile(filePath); // Set data source
});

Use IFluxContext in your app

You can then use Flux normally, as described in the general Flux documentation.