### Install Confix Project-Specifically using .NET Tool Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/1-initial-setup.mdx This command installs the Confix .NET tool specifically for the current project, limiting its scope to the project directory. This requires an existing tool manifest file in the project. ```bash dotnet tool install Confix ``` -------------------------------- ### Install Confix Globally using .NET Tool Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/1-initial-setup.mdx This command installs the Confix .NET tool globally on your machine, making it accessible from any directory. Ensure you have the .NET SDK (version 7.0 or later) installed. ```bash dotnet tool install --global Confix ``` -------------------------------- ### Create .NET Tool Manifest for Project-Specific Confix Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/1-initial-setup.mdx This command initializes a local tool manifest file (`.config/dotnet-tools.json`) in your project directory. This manifest is essential for managing project-specific .NET tool installations. ```bash dotnet new tool-manifest ``` -------------------------------- ### Set Up Local Development Environment for Confix Docs Source: https://github.com/swisslife-oss/confix/blob/main/docs/README.md Instructions for setting up and running the Confix documentation locally. This involves installing Node.js dependencies and starting the development server to view the documentation in a browser. ```Shell npm install npm run dev ``` -------------------------------- ### Build Confix Docker Image with .NET Source: https://github.com/swisslife-oss/confix/blob/main/poc/k8s-deployment/readme.md This command builds the Confix Docker image for Linux x64 architecture using `dotnet publish`. Ensure the Docker tag in `confixDeploymentTest.csproj` is updated before execution. ```PowerShell dotnet publish --os linux --arch x64 /t:PublishContainer -c Release ``` -------------------------------- ### Confix Build Process and Variable Resolution Example Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/4-using-variables.mdx Illustrates the steps involved in processing Confix configurations, including running `confix restore` and the resulting output. It also shows an example of the configuration after variable resolution, where the `$example:Website.Url` variable has been replaced with its actual value. For `appsettings.json`, resolved values are typically stored in user secrets. ```bash cd src/Website confix restore ``` ```json { "Website": { "Url": "mywebsite.com" }, "Database": { "ConnectionString": "Server=myserver;Database=mydatabase;User Id=myuser;Password=mypassword;", "DatabaseName": "mydatabase" } } ``` ```ansi [32m✓ [22;39m Running in scope [1;94mProject [32m✓ [22;39m Configuration loaded [1;32m✓ [22;39m Active Environment is [1;94mprod [32m✓ [22;39m Running in scope [1;94mProject [32m✓ [22;39m Configuration loaded [1;32m✓ [22;39m Active Environment is [1;94mprod [32m✓ [22;39m Component inputs loaded [1;32m✓ [22;39m Loaded 2 components - @dotnet-package/Website - @dotnet-package/Database [1;32m✓ [22;39m Schema composition completed for project src.Website [1;32m✓ [22;39m Schema is stored at '/Users/ex/GettingStarted/.confix/.schemas/src.Website.schema.json' [1;32m✓ [22;39m IntelliJ IDEA settings file updated: /Users/ex/GettingStarted/.idea/.idea.GettingStarted/.idea/jsonSchemas.xml [m ``` -------------------------------- ### Configure .confixrc with Local Variable Provider Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/4-using-variables.mdx This JSON configuration snippet for `.confixrc` demonstrates how to set up the `local` variable provider. It adds a `variableProviders` entry named 'example' of type 'local', pointing to a `variables.json` file relative to the project root. This setup enables Confix to discover variables from the specified local file. ```json { "component": { "inputs": [ { "type": "graphql" }, { "type": "dotnet" } ] }, "project": { "configurationFiles": [ { "type": "appsettings", "useUserSecrets": true } ], "componentProviders": [ { "name": "dotnet", "type": "dotnet-package" } ], "variableProviders": [ { "name": "example", "type": "local", "path": "$project:/variables.json" } ] } } ``` -------------------------------- ### Confix Project Folder Structure Example Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/3-exploring-components.mdx Illustrates the recommended folder structure for a Confix project, including component schemas and project files for Database and Website services, showing how components are organized within the `confix/components` directory. ```plaintext / ├── .confixrc ├── .confix.solution └── src ├── Database │ ├── confix │ │ └── components │ │ └── Database │ │ ├── .confix.component │ │ ├── schema.graphql │ │ └── schema.json │ ├── .confix.project │ ├── DatabaseServiceCollectionExtensions.cs │ └── Database.csproj └── Website ├── confix │ └── components │ └── Website │ ├── .confix.component │ ├── schema.graphql │ └── schema.json ├── .confix.project ├── appsettings.json ├── Program.cs └── Website.csproj ``` -------------------------------- ### Create Kubernetes Namespace and Set Context Source: https://github.com/swisslife-oss/confix/blob/main/poc/k8s-deployment/readme.md These commands create a new Kubernetes namespace named 'confix' and then set the current `kubectl` context to use this namespace as default for subsequent operations. ```Kubernetes k create ns confix k config set-context --current --namespace=confix ``` -------------------------------- ### Example `variables.json` file structure Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/4-using-variables.mdx Shows the structure of the `variables.json` file created by Confix after setting the `$example:Website.Url` variable. This file stores local variables in a JSON format. ```json { "Website": { "Url": "https://localhost:5001" } } ``` -------------------------------- ### Referencing Variables in appsettings.json Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/4-using-variables.mdx Demonstrates how to reference variables within an `appsettings.json` file using the `$example:` syntax. This shows the initial state of the configuration before Confix processing. ```json { "Website": { "Url": "$example:Website.Url" }, "Database": { "ConnectionString": "Server=myserver;Database=mydatabase;User Id=myuser;Password=mypassword;", "DatabaseName": "mydatabase" } } ``` -------------------------------- ### Example Confix Component Definition with Input Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components.mdx This JSON snippet illustrates a basic `.confix.component` file structure, defining a component named 'Logging' with a 'graphql' type input. Inputs act as schema compilers, processing the component's configuration. ```json { "name": "Logging", "inputs": [ { "type": "graphql" // additional properties specific to the graphql compiler } ] } ``` -------------------------------- ### Apply Kubernetes Deployment Manifest Source: https://github.com/swisslife-oss/confix/blob/main/poc/k8s-deployment/readme.md This command applies the Kubernetes deployment definition from the `k8s/deployment.yml` file. This will create or update the specified application deployment within the cluster. ```Kubernetes k apply -f k8s/deployment.yml ``` -------------------------------- ### Push Confix Docker Image to Registry Source: https://github.com/swisslife-oss/confix/blob/main/poc/k8s-deployment/readme.md This command pushes the locally built Docker image to the specified registry. Remember to replace `X.X.X` with the correct version tag and update the tag in `k8s/deployment.yml` as well. ```Docker docker push swisslifef2c/deployment-test:X.X.X ``` -------------------------------- ### Add Component from Registry using Confix CLI Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components/providers.mdx This command shows how to add a component named 'Example' from the 'shared' provider (configured as a Git repository) to your Confix project using the 'confix component add' CLI command. This action invokes the configured provider to locate and add the component. ```bash confix component add @shared/Example ``` -------------------------------- ### Apply Kubernetes Secret Manifest Source: https://github.com/swisslife-oss/confix/blob/main/poc/k8s-deployment/readme.md This command applies the Kubernetes secret definition from the `k8s/secret.yml` file to the currently configured namespace. Secrets are used to store sensitive information. ```Kubernetes k apply -f k8s/secret.yml ``` -------------------------------- ### List Confix Components in JSON Format Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components.mdx This example shows how to use the `confix component list` command with the `--format json` option to retrieve detailed information about all components in a structured JSON format. This is useful for programmatic access or detailed analysis of component configurations. ```bash confix component list --format json ``` ```json { "components": [ { "provider": "dotnet-package", "componentName": "Security", "version": null, "isEnabled": true, "schema": { ... }, "mountingPoints": [ "Security" ] }, { "provider": "dotnet-package", "componentName": "DataProtection", "version": null, "isEnabled": true, "schema": { ... }, "mountingPoints": [ "DataProtection" ] }, { "provider": "dotnet-package", "componentName": "Other", "version": null, "isEnabled": true, "schema": { ... }, "mountingPoints": [ "Other" ] } ] } ``` -------------------------------- ### Set a Confix variable using `confix variable set` Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/4-using-variables.mdx Demonstrates how to set a new variable, `$example:Website.Url`, using the `confix variable set` command. This command prompts for the variable name and value, and creates a `variables.json` file if it doesn't exist. ```bash cd src/Website confix variable set ``` ```ansi [32m✓ [22;39m Running in scope [1;94mProject [32m✓ [22;39m Configuration loaded [1;32m✓ [22;39m Active Environment is [1;94mprod [92m? [22;39m Variable name: $example:Website.Url [1;92m? [22;39m Variable value: [91m************* [1;93m! [22;39m The local variable file was not found at the expected location. Created empty file at: '/Users/ex/GettingStarted/src/Website/variables.json' [1;32m✓ [22;39m Variable [32m$example:Website.Url [39m set successfully. [m ``` -------------------------------- ### Example File System Structure for Local Confix Provider Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components/providers/local.mdx Illustrates the directory structure and key Confix configuration files for a 'Website' component when using the local provider, showing where .confix.component and schema.json are located. ```File System Structure / ├── .confixrc ├── .confix.solution └── src └── Website ├── confix │ └── components │ └── Website │ ├── .confix.component │ └── schema.json ├── .confix.project ├── appsettings.json ├── Program.cs └── Website.csproj ``` -------------------------------- ### Configure Environment Overrides for Confix Variable Providers Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/5-building-environments.mdx This `.confixrc` configuration demonstrates how to use `environmentOverride` within a variable provider. It specifies different `path` values for the 'example' variable provider based on the active environment ('dev' or 'prod'), enabling Confix to load environment-specific variable files. ```json { "component": { ... }, "project": { "environments": [ { "name": "dev" }, { "name": "prod" } ], "configurationFiles": [ ... ], "componentProviders": [ ... ], "variableProviders": [ { "name": "example", "type": "local", "environmentOverride": { "dev": { "path": "$project:/variables.dev.json" }, "prod": { "path": "$project:/variables.prod.json" } } } ] } } ``` -------------------------------- ### Confix Configuration File Referencing Variables Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/variables.mdx This JSON configuration file demonstrates how to embed Confix variables within application settings. It shows examples of referencing variables from different providers (e.g., `keyvault`, `git`, `secret`) for database connection strings, logging levels, and API keys, including an example of a nested variable within a string. ```json { "database": { "connectionString": "$keyvault:database.connectionString", "maxPoolSize": 12 }, "logging": { "level": "$git:logging.level", "destination": "$git:logging.server.url" }, "appSecrets": { "apiKey": "$secret:aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1hM1o3ekVjN0FYUQ==", "jwtSecret": "$vault:jwt.secret" }, "clients": { "baseUrl": "{{$keyvault:api.baseUrl}}/my-endpoint" } } ``` -------------------------------- ### Build Confix Configurations for Multiple Environments Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/6-deploying-your-application.mdx The confix build command replaces placeholders with variable values. When building for multiple environments in a CI/CD pipeline, use the --output-file parameter to specify distinct output files and prevent overwriting. This example builds separate configuration files for 'dev' and 'prod' environments. ```bash confix build --environment=dev --output-file ./appsettings_dev.json confix build --environment=prod --output-file ./appsettings_prod.json ``` -------------------------------- ### Example appsettings.json Initialized from GraphQL Schema Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components/inputs/graphql.mdx This JSON snippet shows the `appsettings.json` file structure after `confix build` processes the GraphQL schema. It reflects the defined fields, including null values for uninitialized fields and populated default values, demonstrating the translation from GraphQL to JSON configuration. ```json { "Website": { "requiredField": null, "nestedType": { "nestedValue": null }, "enumSupport": null, "interfaceSupport": null, "unionSupport": null, "withDefault": "default value", "withVariableDefault": "$shared:common.authority" } } ``` -------------------------------- ### Confix Component File Structure Example Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components.mdx This snippet illustrates the typical file structure for Confix components within a project. Components are saved in the `confix/Components` folder, with each `.confix.component` file defining the component's configuration and a `schema.json` file outlining its structure. ```plaintext / .confixrc .confix.solution src Website confix components Website .confix.component schema.json .confix.project appsettings.json Program.cs Website.csproj ``` -------------------------------- ### Validate Confix Configuration in CI/CD Pipeline Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/6-deploying-your-application.mdx Use the confix validate command to ensure your configuration files are valid, typically in a pull request pipeline before merging. This example validates the configuration for the 'dev' environment. ```bash confix validate --environment=dev ``` -------------------------------- ### Importing Core Nextra UI Components for Documentation Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/5-building-environments.mdx This TypeScript snippet demonstrates how to import essential UI components from the Nextra framework. It includes `Callout` for highlighted content, and `Steps`, `FileTree`, `Tabs`, `Tab` from `nextra-theme-docs` for structuring complex documentation flows, file system representations, and tabbed content sections. These imports are foundational for building rich and interactive documentation pages. ```TypeScript import { Callout } from "nextra/components"; import { Steps, FileTree, Tabs, Tab } from "nextra-theme-docs"; ``` -------------------------------- ### Confix Report Output from GraphQL Dependency Provider Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/reporting/dependency-tracking.mdx Shows an example of the `dependencies` array in the `report.json` when values are extracted using the GraphQL provider, including the `kind`, `path`, and the extracted `value`. ```json { "dependencies": [ { "kind": "auth0.clientId", "path": "/database/connectionString", "value": "123456-1234-1234-123456" } ] } ``` -------------------------------- ### Example Confix Project Report Structure Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/reporting.mdx This JSON snippet illustrates the structure and content of a report generated by the Confix project report command. It includes details about the configuration path, environment, timestamp, project, solution, repository, commit information, and lists of variables and components with their respective details. ```json [ { "configurationPath": "<>/ExampleRepo/src/Host/appsettings.json", "environment": "prod", "timestamp": "2023-01-01T12:00:00.000Z", "project": { "name": "src.Host", "path": "src/Host" }, "solution": { "name": "ExampleRepo", "path": "." }, "repository": { "name": "Confix", "originUrl": "https://github.com/SwissLife-OSS/Confix/_git" }, "commit": { "hash": "025dc307ec300295f563d83af4de34f04e891a5a", "message": "This is an example", "author": "Max", "email": "Sam.Sampleman@gmail.com", "branch": "master", "tags": ["1.0.0", "1.1.0"] }, "variables": [ { "providerName": "foo", "providerType": "local", "name": "test.bool", "hash": "B5BEA41B6C623F7C09F1BF24DCAE58EBAB3C0CDD90AD966BC43A45B44867E12B", "path": "/root/bool" }, { "providerName": "foo", "providerType": "local", "name": "test.string", "hash": "9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08", "path": "/root/string" }, { "providerName": "foo", "providerType": "local", "name": "test.object", "hash": "7A38BF81F383F69433AD6E900D35B3E2385593F76A7B7AB5D4355B8BA41EE24B", "path": "/root/object" } ], "components": [ { "providerName": "__LOCAL", "name": "Test", "version": "latest", "mountingPoints": ["Test"] } ] } ] ``` -------------------------------- ### Monorepo Confix Solution File Structure Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/file-structure.mdx Demonstrates the file structure for a monorepo setup using Confix, where multiple .confix.solution files can exist, along with a root .confixrc for shared configurations across repositories. ```Nextra FileTree ``` -------------------------------- ### Importing FileTree for Confix Documentation Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components/inputs.mdx This snippet shows a typical import statement for `FileTree` from `nextra-theme-docs`, likely used within a Confix project's documentation setup to render file structures. ```TypeScript import { FileTree } from "nextra-theme-docs"; ``` -------------------------------- ### Confix Root Configuration with Multiple Variable Providers Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/variables.mdx This example demonstrates the `variableProviders` array within a `.confixrc` file, showcasing how to configure multiple variable sources. It includes a 'local' provider referencing a JSON file and an 'azure-keyvault' provider with environment-specific URIs for development, QA, and production, enabling flexible secret management across different deployment stages. ```json { "variableProviders": [ { "name": "local", "type": "local", "path": "./variables.json" }, { "name": "keyvault", "type": "azure-keyvault", "environmentOverride": { "dev": { "uri": "https://mykeyvault-dev.vault.azure.net" }, "qa": { "uri": "https://mykeyvault-qa.vault.azure.net" }, "prod": { "uri": "https://mykeyvault-prod.vault.azure.net" } } } ] } ``` -------------------------------- ### Specifying a Single Environment in Confix Project File Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/environments.mdx This JSON example demonstrates a simplified configuration for Confix when an application is deployed to only one environment. The `environments` field directly lists the single environment name, 'development', as a string within an array in a `.confix.project` file. ```json { "environments": ["development"] } ``` -------------------------------- ### Example Local Variables JSON File Structure Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/variables/local.mdx Provides a sample structure for the variables.json file, showcasing various data types including strings, numbers, arrays, and nested objects, which can be accessed using JSON paths like 'faction', 'military.star_destroyers', 'planets[0]', and 'planets[0].name'. ```json { "faction": "Empire", "leader": "Emperor Palpatine", "capital": "Coruscant", "military.star_destroyers": 15, "planets": [ { "name": "Coruscant", "terrain": "Urban", "population": 1000000000000 }, { "name": "Kashyyyk", "terrain": "Forest", "population": 45000000 }, { "name": "Mustafar", "terrain": "Volcanic", "population": 2000 } ], "enemies": ["Rebel Alliance", "Jedi Order"] } ``` -------------------------------- ### GraphQL Schema Annotation for Confix Dependency Tracking Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/reporting/dependency-tracking.mdx Provides an example of annotating a GraphQL schema field (`clientId`) with the `@dependency` directive, specifying its `kind` (`auth0.clientId`), to enable Confix to extract its value as a dependency. ```graphql type Authentication { clientId: String! @dependency(kind: "auth0.clientId") clientSecret: String! } ``` -------------------------------- ### Define Object Types in GraphQL Schema Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components/inputs/graphql.mdx This example demonstrates the definition of a simple GraphQL object type. Object types are translated directly into JSON objects, with their fields becoming properties in the resulting JSON schema. ```graphql type Example { stringField: String! intField: Int! } ``` -------------------------------- ### Defining Multiple Environments in Confix Configuration Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/environments.mdx This JSON example illustrates how to define multiple distinct environments, 'development' and 'production', within a Confix configuration file such as `.confixrc`. Each environment is represented as an object with a `name` property, enabling separate configuration management for different deployment stages. ```json { "environments": [ { "name": "development" }, { "name": "production" } ] } ``` -------------------------------- ### Define Environments in .confixrc Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/5-building-environments.mdx This JSON configuration for `.confixrc` explicitly defines 'dev' and 'prod' environments within the project settings. This allows Confix to manage environment-specific configurations, such as variable values, ensuring different behaviors for development and production deployments. ```json { "component": { ... }, "project": { "environments": [ { "name": "dev" }, { "name": "prod" } ], "configurationFiles": [ ... ], "componentProviders": [ ... ], "variableProviders": [ { "name": "example", "type": "local", "path": "$project:/variables.json" } ] } } ``` -------------------------------- ### Set Confix Variable for a Specific Environment via CLI Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/5-building-environments.mdx This `confix` CLI command sets a variable for the 'prod' environment. The `--environment` flag ensures that the operation applies to the specified environment, triggering the loading of environment-specific variable files as configured in `.confixrc`. ```bash confix variable set --environment prod ``` -------------------------------- ### Confix Dotnet Input Configuration Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components/inputs/dotnet.mdx This JSON configuration snippet shows how to add the `dotnet` input type to the `inputs` array within the `component` section of a `.confixrc` file. This setup is essential for ensuring embedded resources are included when distributing components in a package. ```json { "component": { "inputs": [ { "type": "dotnet" } ] } } ``` -------------------------------- ### Example GraphQL Schema for Configuration Definition Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components/inputs/graphql.mdx This comprehensive GraphQL schema defines the structure for a configuration, including required and optional fields, nested types, enums, interfaces, and unions. It also showcases the use of custom scalar types like Date, UUID, and Regex, and the `@defaultValue` directive for setting initial values. ```graphql type Configuration { requiredField: String! optionalField: String nestedType: NestedType! enumSupport: Kind! interfaceSupport: ExampleInterface! unionSupport: ExampleUnion! date: Date uuid: UUID regex: Regex withDefault: String @defaultValue(value: "default value") withVariableDefault: String @defaultValue(value: "$shared:common.authority") } type NestedType { nestedValue: String! } enum Kind { KindA KindB } interface ExampleInterface { interfaceField: String! } type ExampleA implements ExampleInterface { interfaceField: String! typeAField: String! } type ExampleB implements ExampleInterface { interfaceField: String! typeBField: String! } union ExampleUnion = ExampleA | ExampleB ``` -------------------------------- ### Configure Git Variable Provider in .confixrc Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/variables/git.mdx This JSON configuration snippet illustrates how to set up the 'git' variable provider within a Confix project's .confixrc file. It defines the repository URL, the relative path to the JSON variables file within that repository, and optional arguments for the 'git clone' command, such as specifying a branch or clone depth. This setup enables Confix to retrieve variables directly from a specified Git repository. ```json { "project": { "variableProviders": [ { "name": "git", "type": "git", "repositoryUrl": "https://github.com/SwissLife-OSS/Confix-Variables.git", "filePath": "./variables.json", "arguments": ["--branch=main", "--depth=1"] } ] } } ``` -------------------------------- ### Initialize Confix Project and Component for Database Package Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/3-exploring-components.mdx These `confix` CLI commands initialize a new Confix project within the 'src/Database' directory and then create a new Confix component named 'Database'. This sets up the necessary Confix metadata for managing the configuration of the shared database component. ```bash cd src/Database confix project init confix component init Database ``` -------------------------------- ### Registering Database Service in ASP.NET Core Program.cs Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/3-exploring-components.mdx Demonstrates how to register the `Database` service and configure a basic ASP.NET Core application startup in `Program.cs`. It's crucial to actively use the package in your code, as merely referencing it is insufficient; otherwise, .NET's treeshaking might exclude it from the final build. ```csharp using Database; var builder = WebApplication.CreateBuilder(args); builder.Services.AddDatabase(); var app = builder.Build(); app.MapGet("/", () => "Hello World!"); app.Run(); ``` -------------------------------- ### Confix CLI Output for Adding Component Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components/providers.mdx This ASCII output illustrates the successful execution of the 'confix component add' command, showing the steps taken by Confix, including loading configuration and inputs, and confirming that the component '@shared/Example' was successfully added to the project. ```ascii ✓ Running in scope Project ✓ Configuration loaded ✓ Component inputs loaded ✓ Component '@shared/Example' was added ``` -------------------------------- ### Initialize Local Confix Component Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/3-exploring-components.mdx Use the `confix component init` command to create a new local component within a specified application folder. This command sets up the necessary directory structure and a `.confix.component` file, providing the foundation for defining a component-specific configuration schema. ```bash confix component init Website ``` -------------------------------- ### Initialize Confix Solution for Project Root Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/2-first-configuration.mdx This `bash` command initializes a Confix solution, typically executed in the root directory of a project or repository. It establishes the top-level configuration context, enabling proper intellisense for variables and schema across multiple projects within the solution. ```bash confix solution init ``` -------------------------------- ### Create a New .NET Class Library for the Database Component Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/3-exploring-components.mdx This command sequence creates a new .NET class library named 'Database' within the 'src' directory and adds the 'Microsoft.Extensions.DependencyInjection' NuGet package, which is often required for dependency injection in .NET applications. ```bash cd src dotnet new classlib -n Database cd Database dotnet add package Microsoft.Extensions.DependencyInjection ``` -------------------------------- ### Initialize a New Confix Component Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components/inputs.mdx This 'confix' CLI command initializes a new component named 'Authorization' within the current project directory where a '.confix.project' file exists. It generates the necessary '.confix.component' file and sets up the component's basic structure. ```bash confix component init Authorization ``` -------------------------------- ### Build Confix Project and Validate Configuration Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/3-exploring-components.mdx Run `confix build` to process the project's configuration. This command loads defined components, composes their schemas, and validates configuration files against these schemas, reporting any discrepancies or errors found in the configuration. ```bash confix build ``` -------------------------------- ### Initialize Confix Project for Specific Folder Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/2-first-configuration.mdx This `bash` command initializes a Confix project within a designated project folder, such as 'Website' in a .NET application. It defines the specific configuration scope for files like `appsettings.json` within that particular project, allowing for granular control. ```bash confix project init ``` -------------------------------- ### Confix Build Command Execution and Validation Output Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/4-using-variables.mdx This output demonstrates the successful execution of the `confix build` command. It shows the loading of configurations, schema composition, and validation of `appsettings.json` files. The output also indicates the detection of projects, components, active environment, and the final validation status, noting that initially no variables were detected. ```ansi [32m✓ [22;39m Running in scope [1;94mSolution [32m✓ [22;39m Configuration loaded [1;32m✓ [22;39m Running in scope [1;94mComponent [32m✓ [22;39m Configuration loaded [1;32m✓ [22;39m Component inputs loaded Building component... Building component completed [1;32m✓ [22;39m Running in scope [1;94mComponent [32m✓ [22;39m Configuration loaded [1;32m✓ [22;39m Component inputs loaded Building component... Building component completed Project detected: Database [2m/Users/ex/GettingStarted/src/Database/.confix.project [1;32m✓ [22;39m Running in scope [1;94mProject [32m✓ [22;39m Configuration loaded The project directory '/Users/ex/GettingStarted/src/Database' will be treated as a component only project as it does not contain a appsettings.json file. [1;32m✓ [22;39m Active Environment is [1;94mprod [22;39m Skipped command execution build because no configuration files were found. Project detected: Website [2m/Users/ex/GettingStarted/src/Website/.confix.project [1;32m✓ [22;39m Running in scope [1;94mProject [32m✓ [22;39m Configuration loaded [1;32m✓ [22;39m Active Environment is [1;94mprod [32m✓ [22;39m Component inputs loaded [1;32m✓ [22;39m Loaded 2 components - @dotnet-package/Website - @dotnet-package/Database [1;32m✓ [22;39m Schema composition completed for project src.Website [1;32m✓ [22;39m Schema is stored at '/Users/ex/GettingStarted/.confix/.schemas/src.Website.schema.json' [1;32m✓ [22;39m IntelliJ IDEA settings file updated: /Users/ex/GettingStarted/.idea/.idea.GettingStarted/.idea/jsonSchemas.xml [1;94mi [22;39m Loaded schema from [1mcache [22m for project src.Website Persisting configuration file '/Users/ex/.microsoft/usersecrets/f736895a-96b8-471a-8502-09b0e07dfdb8/secrets.json' Detected [1;94m0 [22;39m variables [1;32m✓ [22;39m The configuration file '/Users/ex/GettingStarted/src/Website/appsettings.json' is valid. Persisting configuration file '/Users/ex/.microsoft/usersecrets/f736895a-96b8-471a-8502-09b0e07dfdb8/secrets.json' [m ``` -------------------------------- ### Add Project Reference to the Shared Database Component Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/3-exploring-components.mdx This `dotnet` CLI command adds a project reference from the 'Website' project to the 'Database' class library. This allows the 'Website' project to consume the shared database component and its associated configuration. ```bash cd src/Website dotnet add reference ../Database ``` -------------------------------- ### Sample Confix Git Component Provider Configuration Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components/providers/git.mdx This JSON snippet illustrates a sample configuration for the Git component provider within the `.confixrc` file. It defines the provider's name, type, the URL to clone the repository, the path to components within that repository, and optional arguments for `git clone` such as specifying a branch or depth. ```json { "project": { "componentProviders": [ { "name": "shared-components", "type": "git", "repositoryUrl": "https://github.com/SwissLife-OSS/Confix-Components.git", "path": "Components", "arguments": ["--branch=main", "--depth=1"] } ] } } ``` -------------------------------- ### Initialize New Confix Component Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components.mdx Use the `confix component init` command to create a new component definition within your `.confix.project` file. This command initializes the necessary structure for a new component, ready for further configuration. ```bash confix component init my-component-name ``` -------------------------------- ### Confix Build Command Console Output Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/3-exploring-components.mdx Displays the console output from running `confix build`, showing successful configuration loading, project detection, component loading, schema composition, and updates to IDE settings. ```ansi [32m✓ [22;39m Running in scope [1;94mSolution [32m✓ [22;39m Configuration loaded Project detected: Website [2m/Users/ex/confix/examples/GettingStarted/src/Website/.confix.project [1;32m✓ [22;39m Running in scope [1;94mProject [32m✓ [22;39m Configuration loaded [1;32m✓ [22;39m Active Environment is [1;94mprod [22;39m [1;32m✓ [22;39m Component inputs loaded [1;32m✓ [22;39m Loaded 2 components - @dotnet-package/Website - @dotnet-package/Database [1;32m✓ [22;39m Schema composition completed for project src.Website [1;32m✓ [22;39m Schema is stored at '/Users/ex/confix/examples/GettingStarted/.confix/.schemas/src.Website.schema.json' [1;32m✓ [22;39m IntelliJ IDEA settings file updated: /Users/ex/confix/examples/GettingStarted/.idea/.idea.GettingStarted/.idea/jsonSchemas.xmlg the schemas configuration for IDE... [1;94mi [22;39m Loaded schema from [1mcache [22m for project src.Website Persisting configuration file '/Users/ex/.microsoft/usersecrets/f736895a-96b8-471a-8502-09b0e07dfdb8/secrets.json' Detected [1;94m0 [22;39m variables ``` -------------------------------- ### Confix Variable Provider Sample Configuration Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/variables.mdx This JSON snippet illustrates a basic Confix variable provider definition. It shows how to name a provider, specify its type (e.g., 'local'), define a `path` to a variables file, and use `environmentOverride` to specify a different path for the 'dev' environment, ensuring environment-specific variable resolution. ```json { "name": "local", "type": "local", "path": "./variables.json", "environmentOverride": { "dev": { "path": "./variables.dev.json" } } } ``` -------------------------------- ### Initialize Confix Configuration File (.confixrc) Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/2-first-configuration.mdx This JSON snippet provides the basic structure for a new `.confixrc` file, which serves as the central configuration for Confix. Placed in the project's root, it defines empty `component` and `project` sections, ready for further configuration. ```json { "component": {}, "project": {} } ``` -------------------------------- ### Confix Build Command Output Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/2-first-configuration.mdx This snippet displays the console output when running the `confix build` command in a Confix project. It shows the detection of the 'Website' project, loading of configurations, activation of the 'prod' environment, and validation of the `appsettings.json` file. The output confirms successful schema composition and storage. ```Shell ✓ 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. ``` -------------------------------- ### List All Confix Components Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components.mdx The `confix component list` command displays a summary of all components currently configured in your project. It provides a quick overview of available components. ```bash confix component list ``` -------------------------------- ### Restore Confix variables for Intellisense Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/4-using-variables.mdx Explains how to run `confix restore` to make defined variables available for Intellisense in configuration files. This command processes components, generates schemas, and updates IDE settings. ```bash cd src/Website confix restore ``` ```ansi [32m✓ [22;39m Running in scope [1;94mProject [32m✓ [22;39m Configuration loaded [1;32m✓ [22;39m Active Environment is [1;94mprod [32m✓ [22;39m Running in scope [1;94mProject [32m✓ [22;39m Configuration loaded [1;32m✓ [22;39m Active Environment is [1;94mprod [32m✓ [22;39m Component inputs loaded [1;32m✓ [22;39m Loaded 2 components - @dotnet-package/Website - @dotnet-package/Database [1;32m✓ [22;39m Schema composition completed for project src.Website [1;32m✓ [22;39m Schema is stored at '/Users/ex/GettingStarted/.confix/.schemas/src.Website.schema.json' [1;32m✓ [22;39m IntelliJ IDEA settings file updated: /Users/ex/GettingStarted/.idea/.idea.GettingStarted/.idea/jsonSchemas.xml [m ``` -------------------------------- ### List all defined Confix variables Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/4-using-variables.mdx Illustrates how to use the `confix variable list` command to display all currently defined variables within the project scope. The output shows the variable names and their hierarchical structure. ```bash confix variable list ``` ```ansi [32m✓ [22;39m Running in scope [1;94mProject [32m✓ [22;39m Configuration loaded [1;32m✓ [22;39m Active Environment is [1;94mprod [22;39m $example:Website $example:Website.Url [m ``` -------------------------------- ### Define an Extension Method for Database Service Registration Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/3-exploring-components.mdx This C# code defines an extension method `AddDatabase` for `IServiceCollection`. While currently empty, this method serves as an entry point for registering database-related services and components within the .NET dependency injection container, making the component discoverable. ```csharp using Microsoft.Extensions.DependencyInjection; namespace Database; public static class DatabaseServiceCollectionExtensions { public static void AddDatabase(this IServiceCollection services) { // nothing to do here } } ``` -------------------------------- ### Configure Confix Component Repository with Git Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components.mdx This configuration shows how to set up a `git` component repository in your `.confixrc` file. This is useful when component schemas cannot be bundled with the code or require independent versioning, allowing components to be loaded from a specified Git repository path. ```json { "componentProviders": [ { "name": "oss-components", "type": "git", "url": "git@github.com:SwissLife-OSS/template.git", "path": "Components" } ] } ``` -------------------------------- ### Build Confix Project and Validate Configuration Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components/inputs.mdx This 'confix' CLI command builds the entire Confix project, generating component schemas and validating existing configuration files like 'appsettings.json'. It will report errors if required sections, such as 'Authorization', are missing based on the defined schemas. ```bash confix build ``` -------------------------------- ### Configure GraphQL Input Provider in Confix RC Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/3-exploring-components.mdx This JSON configuration snippet shows how to enable the `graphql` input provider within the `.confixrc` file, allowing Confix to process GraphQL files for schema generation. It also configures `appsettings` as a configuration file type with user secrets enabled. ```json { "component": { "inputs": [ { "type": "graphql" } ] }, "project": { "configurationFiles": [ { "type": "appsettings", "useUserSecrets": true } ] } } ``` -------------------------------- ### C# Extension Method for Database Service Registration Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/3-exploring-components.mdx Provides an extension method `AddDatabase` for `IServiceCollection`, allowing easy registration of database-related services in a .NET application's dependency injection container, even if the current implementation is a placeholder. ```csharp using Microsoft.Extensions.DependencyInjection; namespace Database; public static class DatabaseServiceCollectionExtensions { public static void AddDatabase(this IServiceCollection services) { // nothing to do here } } ``` -------------------------------- ### Normal Confix Solution File Structure Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/file-structure.mdx Illustrates the typical file organization for a single Confix solution, showing the placement of .confix.solution, .confix.project, and application configuration files within a repository. ```Nextra FileTree ``` -------------------------------- ### Available Confix Component Providers Reference Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components/providers.mdx This section provides a reference for the available component providers in Confix, detailing their names and a brief description of their functionality. It includes providers like 'dotnet-package' for .NET packages and 'git' for Git repositories. ```APIDOC Component Providers: - dotnet-package: Description: Lets confix discover components from .NET packages - git: Description: Defines a git repository with confix components ``` -------------------------------- ### Confix Build Output: Configuration Validation Errors Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/3-exploring-components.mdx This output from `confix build` illustrates configuration validation failures. It shows that while components and schemas are loaded, the `appsettings.json` file is invalid because the 'Url' property, which is required to be a string, is currently set to `null`, leading to a validation error. ```ansi [32m✓ [22;39m Running in scope [1;94mProject [32m✓ [22;39m Configuration loaded [1;32m✓ [22;39m Active Environment is [1;94mprod [22;39m [1;32m✓ [22;39m Component inputs loaded [1;32m✓ [22;39m Loaded 1 components - Website [1;32m✓ [22;39m Schema composition completed for project src.Website [1;32m✓ [22;39m Schema is stored at '/Users/ex/Confix/examples/GettingStarted/.confix/.schemas/src.Website.schema.json' [1;94mi [22;39m Loaded schema from [1mcache [22m for project src.Website Persisting configuration file '/Users/ex/.microsoft/usersecrets/f736895a-96b8-471a-8502-09b0e07dfdb8/secrets.json' Detected [1;94m0 [22;39m variables [1;91m✕ The configuration file '/Users/ex/Confix/examples/GettingStarted/src/Website/appsettings.json' is invalid. [22;39m └── [93mWebsite [39m └── [93mUrl [39m ├── [1;91m✕ [22;39m Value is "null" but should be "string" └── [1;91m✕ [22;39m Expected value to match one of the values specified by the enum [1;91m✕ Confix failed. [22;39m [91mThe configuration files are invalid. [m ``` -------------------------------- ### Define GraphQL Schema for Confix Input Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/getting-started/3-exploring-components.mdx This GraphQL schema defines the structure for `Configuration` and `Database` types, including required string fields. Confix uses this schema as an input to generate a corresponding JSON schema, ensuring data consistency based on the GraphQL definition. ```graphql type Configuration { Url: String! Database: Database! } type Database { ConnectionString: String! DatabaseName: String! } ``` -------------------------------- ### Configure Confix Component Discovery with dotnet-package Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components.mdx This JSON configuration snippet demonstrates how to define a `dotnet-package` component provider in your `.confixrc` file. This provider automatically scans project assemblies for embedded Confix components, ensuring that the component schema is versioned together with your code. ```json { "componentProviders": [ { "name": "dotnet", "type": "dotnet-package" } ] } ``` -------------------------------- ### Configure Specific Projects with .confix.project Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/file-structure.mdx The .confix.project file is used for configuring individual projects. It allows defining project name, environments (e.g., dev, prod), components with versions, configuration files (e.g., appsettings with user secrets), component providers, and variable providers with their paths. ```json { "name": "MyProject", "environments": [ { "name": "dev" }, { "name": "prod" } ], "components": { "@shared-components/Example": "latest" }, "configurationFiles": [ { "type": "appsettings", "useUserSecrets": true } ], "componentProviders": [ { "name": "dotnet", "type": "dotnet-package" } ], "variableProviders": [ { "name": "local", "type": "local", "path": "$project:/variables.A.json" } ] } ``` -------------------------------- ### Confix Component Inputs Reference Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/components/inputs.mdx A detailed reference of the component inputs available in Confix, explaining their purpose and how they are used within the project. ```APIDOC Component Inputs: graphql: Allows you to define a graphql file which can be used to define the json schema dotnet: This will add the components as an embedded resource to the .net project that defines the component ``` -------------------------------- ### Encrypt Confix Configuration Files Source: https://github.com/swisslife-oss/confix/blob/main/docs/pages/deployments.mdx This snippet demonstrates how to encrypt configuration files using Confix. The `confix build` command with the `--encrypt` flag or the `confix encrypt` command can be used. This strategy is particularly useful for containerized applications to prevent embedding plaintext secrets in the container image at build time. ```bash confix build --environment=dev --output-file ./appsettings_dev.json.enc --encrypt # or confix encrypt ./appsettings_dev.json ./appsettings_dev.json.enc ```