Your First Configuration
This guide will walk you through setting up a simple .net core project (opens in a new tab) to show you how to work with Confix. Confix is versatile and can work with any language or framework, making it a handy tool for your project aswell.
There might be some limitations depending on your particular needs. Feel free to get in touch with us if you're keen on using Confix with your preferred framework, and we'll be happy to help. Open an issue (opens in a new tab)
In this guide, we'll be building on the same project step by step, introducing new features as we go along. To kick things off, you can find the starting point of the guide here: starting point (opens in a new tab)
Confix operates as a modular configuration system, meant to adapt to diverse needs with the potential for expansion to cover new requirements. Like with other modular systems, a bit of initial setup is required to align Confix with your project's needs.
The configuration details for Confix are in a file named .confixrc
. This file is organized into
two main sections; namley "component" and "project".
- The "component" section defines configuration for Confix Components
- In the "project" section, you can define configuration for your project
As we navigate through this guide, we'll delve into various configuration options to give you a good grasp of what's possible.
Getting started with Confix is straightforward. Simply create a .confixrc
file in the root
directory of your project and fill it with the following content:
{
"component": {},
"project": {}
}
As we are configuring a .NET application, we want to use appsettings.json
as our configuration
source. Confix has a way to understand different types of "configurationFiles" (Configuration
Files). In the example of a
.NET application, we can define a configuration file with the type "appsettings". The nice thing
about this is that additionally to just a json file, we also get support for user secrets, which is
a great way to keep sensitive data out of your repository.
{
"component": {},
"project": {
"configurationFiles": [
{
"type": "appsettings",
"useUserSecrets": true
}
]
}
}
Now that we've established a configuration file, it's time to specify the root of our project and its location.
In Confix terminology, the project root is referred to as the solution
. A solution
can encompass
one or more projects
. Typically, if you have a git repository, the solution
is the root of the
project. However, in a monorepo setup, you might have multiple solutions. A good rule of thumb is to
set up the solution
in the folder you usually open in your editor. This way, the intellisense for
variables and schema will function properly.
Initiating a solution
is done with a simple command in the root:
confix solution init
On the flip side, a project
refers to the folder where your project file resides.
For instance, in our scenario, it's the Website
folder.
The project folder outlines the configuration scope (like appsettings.json
in this case).
If your solution
houses multiple projects, you can designate a project for each.
confix project init
When we run confix build
in the root we now see that it detects our project
✓ Running in scope Solution
✓ Configuration loaded
Project detected: Website /GettingStarted/src/Website/.confix.project
✓ Running in scope Project
✓ Configuration loaded
✓ Active Environment is prod
✓ Component inputs loaded
✓ Loaded 0 components
✓ Schema composition completed for project src.Website
✓ Schema is stored at '/GettingStarted/.confix/.schemas/src.Website.schema.json'
i Loaded schema from cache for project src.Website
Detected 0 variables
✓ The configuration file '/GettingStarted/src/Website/appsettings.json' is valid.