---
title: "Configuration"
description: "The configuration root, the settings file of a domain, environment variables, the settings, the templates and the admin connections."
audience: "Users"
kind: "Reference"
status: "Current"
version: "main · v3.2 (unreleased)"
slug: "configuration"
url: "https://docs.allors.com/allors3/configuration/"
---

# Configuration

> **Status: Current.** [Where this is implemented](#where-this-is-implemented) names the code and the tests.

A server, the command-line tool and the tests that need settings read one file: the `appsettings.json` of their domain, below the configuration root. Environment variables override that file. No `appsettings` file is read from the folder of a project.

<a id="the-configuration-root"></a>

## The configuration root

The configuration root is the folder that the environment variable `ALLORS_CONFIG_ROOT` names. Below it every domain has a folder, and that folder holds the settings of the domain’s programs in one file, `appsettings.json`:

```text
<configuration root>/core/appsettings.json
<configuration root>/custom/appsettings.json
```

A program names the folder of its domain when it calls `AddAllorsConfiguration`. Core’s folder is `core`, and the sample’s is `custom`, after its domain; an application that starts from the sample keeps that name or passes one of its own. The command-line tool and the server of an application read the same file.

| Program | Reads |
| --- | --- |
| The Core test server, its command-line tool, the local API tests and the local workspace tests | `core/appsettings.json` |
| The domain tests of Core | `core/appsettings.json`. They run on the Memory adapter unless the setting `adapter` names SQL Server or PostgreSQL. |
| The sample’s command-line tool and server, and the tests that run them | `custom/appsettings.json` |

The domain tests of the sample read no configuration root; [Test on PostgreSQL or SQL Server](https://docs.allors.com/allors3/test-on-postgresql-or-sql-server.md) says how they choose their adapter.

The configuration root is mandatory, and nothing takes its place: no program, no test and no build falls back to another folder. A program stops with a message when `ALLORS_CONFIG_ROOT` is not set, when its value is not an absolute path, and when the file of its domain does not exist:

```text
ALLORS_CONFIG_ROOT is not set. Set it to the folder that holds 'core/appsettings.json'.
```

A relative path is refused because it names another folder for every working directory.

Nothing else in the folder of a domain is read: no file for an environment, such as `appsettings.Development.json`, no file for an operating system, and no folder below it.

The Core test server and the sample server read no setting from the command line except `--urls`, which sets their listening addresses.

<a id="environment-variables"></a>

## Environment variables

Environment variables override the file. In the name of a variable two underscores separate the levels of a setting:

Terminal window

```sh
export adapter=npgsql
export ConnectionStrings__DefaultConnection='Host=localhost;Database=core;Username=allors;Password=…'
export JwtToken__Key=…
```

A variable holds for every program that starts in that environment, whatever its domain. A setting that only the server of an application needs, such as the signing key, can be given to the server alone in this way.

<a id="settings"></a>

## Settings

| Setting | Read by | Meaning |
| --- | --- | --- |
| `adapter` | Every program | The database adapter: `snapshot`, `sqlclient` or `npgsql`. Upper and lower case are equal. [The database adapters](https://docs.allors.com/allors3/database-adapters.md) explains the choice. |
| `ConnectionStrings:DefaultConnection` | Every program | The connection string of the database. Required with `sqlclient` and `npgsql`; the Snapshot adapter keeps its population in memory and needs none. |
| `JwtToken:Key` | A server | The key that signs and validates bearer tokens. The server requires at least 32 UTF-8 bytes at startup. [The token](https://docs.allors.com/allors3/authentication.md#the-token) describes the tokens and these settings. |
| `JwtToken:Issuer` | A server | The issuer of a bearer token. When the setting has a value, a request with a token from another issuer receives HTTP 401. |
| `JwtToken:Audience` | A server | The audience of a bearer token. Without the setting it is the issuer. When the audience has a value, a request with a token for another audience receives HTTP 401. |
| `JwtToken:Expiration` | A server | The lifetime of a bearer token, as a .NET `TimeSpan` such as `7.00:00:00` for seven days. Without a value that is a `TimeSpan`, the lifetime is 30 days. |
| `AllowedHosts` | The sample server | A semicolon-separated list of host names without ports. An explicit list replaces the default, `localhost`. Every accepted host uses the `Default` workspace. An unlisted host receives HTTP 400 before authentication. |
| `populationFile` | The command-line tool | The file that `load` reads and `save` writes, and that the `upgrade` of the sample application reads, when the `-f` option is absent. Without the setting the file is `population.xml`. |
| `datapath` | The command-line tool of Core | The name of a folder. The tool looks for a folder of that name next to its working directory, and then next to each folder above it, and passes it to the setup of `populate` and to `upgrade`. Core’s own setup does not read it. |

A program stops when a setting that it needs has no value. The message names the setting, the file of the domain and the environment variable:

```text
The configuration has no value for 'adapter'. Add the value to '/srv/allors/core/appsettings.json', or set 'adapter' in the environment.
```

<a id="templates"></a>

## Templates

The repository holds four templates for a configuration root. Point `ALLORS_CONFIG_ROOT` at one of them, or at a copy that holds your own values:

Terminal window

```sh
export ALLORS_CONFIG_ROOT="$PWD/config/snapshot"
```

| Template | Adapter | Database |
| --- | --- | --- |
| `config/snapshot` | `snapshot` | None. The Snapshot adapter keeps the population in memory and needs no connection string. |
| `config/sqlclient` | `sqlclient` | SQL Server on `localhost`, with the login `allors`. |
| `config/npgsql` | `npgsql` | PostgreSQL on `localhost`, with the login `allors`. |
| `config/localdb` | `sqlclient` | SQL Server LocalDB on Windows, with Windows authentication. |

Each template holds `core/appsettings.json`. The template `config/snapshot` holds `custom/appsettings.json` as well, for the tests that run the sample’s command-line tool and server.

The templates are for development and testing. Their signing key and their passwords are published in the repository: give a deployment its own values.

With the Snapshot adapter a population lasts as long as its process. A population that the command-line tool builds ends with the tool, and the Core test server builds its own through its endpoint `Test/Setup`.

<a id="admin-connections"></a>

## Admin connections

`ALLORS_SQLCLIENT` and `ALLORS_NPGSQL` hold an admin connection to the server of the configured database: SQL Server for `sqlclient`, PostgreSQL for `npgsql`. They serve database management only; no program runs on them.

-   The `init` command of Core’s command-line tool drops and creates the database of the configured connection. When that connection names a user, and on SQL Server does not use integrated security, `init` makes the login of that user the owner of the database, and creates the login when the server does not know it. Otherwise the database belongs to the user of the admin connection. With the Snapshot adapter `init` has nothing to drop or create. The command calls `DatabaseProvisioning.DropCreate`, which the command-line tool of an application can call as well.
-   The adapter test suites create and open their test databases with the admin connection.
-   The domain tests of the sample create and open their database with it when `ALLORS_TEST_ADAPTER` names `sqlclient` or `npgsql`; see [Test on PostgreSQL or SQL Server](https://docs.allors.com/allors3/test-on-postgresql-or-sql-server.md).
-   Without the variable of its adapter, database management stops with a message that names the variable. SQL Server LocalDB is named like any other server: `Server=(localdb)\MSSQLLocalDB;Integrated Security=true;TrustServerCertificate=true`.

Terminal window

```sh
export ALLORS_CONFIG_ROOT="$PWD/config/sqlclient"
export ALLORS_SQLCLIENT='Server=localhost;User Id=sa;Password=…;TrustServerCertificate=true'
```

<a id="where-this-is-implemented"></a>

## Where this is implemented

-   `ConfigurationBuilderExtensions`, in `dotnet/Core/Database/Configuration/Core`, reads the file of a domain in `AddAllorsConfiguration`, and builds the message for a missing setting in `Require`. `ConfigurationBuilderExtensionsTests`, in `dotnet/Core/Database/Server.Local.Tests`, checks that the configuration stops without a configuration root, with a relative one and without the file of the domain, that no other file is read, the override by environment variables and `Require`.
-   `DatabaseBuilder` and `DatabaseProvisioning`, in `dotnet/System/Database/Adapters/Allors.Database.Builder`, select the adapter and manage the database through the admin connection.
-   `Program` of `dotnet/Core/Database/Server` and `Program` of `dotnet/Core/Database/Commands` name the folder of the Core test server and of its command-line tool, `core`.
