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.
-
Clone the fig repository and use the
docker-compose.yml
file included. -
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
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.
- Create new ASP.NET project
dotnet new webapi
-
Open the project in your favourite IDE
-
Add Fig.Client nuget package. You might want to add a secret provider nuget package too
-
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;
} -
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
}); -
Register Fig with the host:
builder.Host.UseFig<Settings>();
-
Access the settings via the
IOptions
orIOptionsMonitor
interface. E.g.public WeatherForecastController(IOptionsMonitor<ExampleSettings> settings)
{
_settings = settings;
} -
Add an environment variable called
FIG_API_URI
with the URI of the Fig API. For example:FIG_API_URI=https://localhost:7281
-
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.