Skip to main content
Version: Next

Introduction

Quick Start

To get up and running with Fig, you'll need to set up the API, Web and integrate the Fig.Client nuget package into your application.

Install API and Web Client

The API and Web Clients can be installed using Docker. This guide assumes docker is installed and running.

  1. Clone the fig repository and use the docker-compose.yml file included.

  2. Open a terminal / command prompt, navigate to the directory containing the docker-compose file and type docker-compose up to download the containers and run them.

Log in to Web Client

Navigate to http://localhost:7148 and at the login prompt enter user: admin password: admin. You should see the administration view of fig with all options available.

Integrate Client

tip

In this guide, we'll create an ASP.NET project from scratch and integrate the Fig.Client to use fig for configuration. However the same instructions apply if you have an existing project. Just skip the project creation.

  1. Create new ASP.NET project
dotnet new webapi
  1. Open the project in your favourite IDE

  2. Add Fig.Client nuget package. You might want to add a secret provider nuget package too

  3. Create a new class to hold your application settings, extending the SettingsBase class. For example:

    public class ExampleSettings : SettingsBase
    {
    public override string ClientName => "ExampleService";

    [Setting("My favourite animal")]
    public string FavouriteAnimal { get; set; } = "Cow"

    [Setting("My favourite number")]
    public int FavouriteNumber { get; set; } = 66;

    [Setting("True or false, your choice...")]
    public bool TrueOrFalse { get; set; } = true;
    }
  4. Register Fig as a configuration provider in the program.cs file.

    builder.Configuration.SetBasePath(GetBasePath())
    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
    .AddFig<Settings>(options =>
    {
    options.ClientName = "AspNetApi";
    options.LoggerFactory = loggerFactory;
    options.CommandLineArgs = args;
    //options.ClientSecretProviders = [new DockerSecretProvider(), new DpapiSecretProvider()]; // if you added a secret provider
    o.ClientSecretOverride = "be633c90474448c382c47045b2e172d5xx"; // not for production use, use a secret provider
    });
  5. Register Fig with the host:

builder.Host.UseFig<Settings>();
  1. Access the settings via the IOptions or IOptionsMonitor interface. E.g.

    public WeatherForecastController(IOptionsMonitor<ExampleSettings> settings)
    {
    _settings = settings;
    }
  2. Add an environment variable called FIG_API_URI with the URI of the Fig API. For example:

    FIG_API_URI=https://localhost:7281
  3. Add a client secret (see Client Secrets section for details on how to do that)

See the examples folder in the source repository for more examples.

Example Setup using WSL

fig-local-machine-setup