Configurations
To store configurations, we use a database table named config
.
Configurations are stored as key, value.
Key column
Naming key convention
{module}.{entity}.{confingName}
Example : Jobs.Job.JobPostingProductId
Value column
Values are stored as string. For other types, they are stored as string but can be cast.
Values are nullable and will be edited by the administrator.
Type column
We store the real type of the value to help manage the value in the validations and in the frontEnd.
Description column
We also have a description field that is optional that will be very useful for the administrator to know exactly what a config does before updating it.
Add new configurations for a module
Each module adds it's own configuration to kkep the app modular.
Modules need to add a service that implement IConfigSeeder from the Config module.
When this module is added to the scope in the installer, it will automatically be selected in Program.cs
at the line scope.ServiceProvider.GetServices<IConfigSeeder>();
In the function SeedModules
from Startup.cs
every seeders from all modules will add their own configs to the database by calling the ConfigService
in Config module.
Example :
using QuebecMunicipal.Modules.Core.Interfaces;
using QuebecMunicipal.Modules.Core.Models;
using QuebecMunicipal.Modules.Core.Services;
namespace QuebecMunicipal.Modules.Jobs.Services;
public class JobConfigSeeder : IConfigSeeder
{
private readonly IConfigService _configService;
public JobConfigSeeder(IConfigService configService)
{
_configService = configService;
}
public async Task SeedConfigs()
{
List<Config> configs = new()
{
new()
{
Key = "Jobs.Job.JobPostingsAvailable",
Value = null,
Type = "int",
Description = "Le nombre d'affichages d'emplois disponible par année pour les organisations membres."
},
new()
{
Key = "Jobs.Job.JobPostingProductId",
Value = null,
Type = "int",
Description = "Le produit pour la vente d'affichage d'emplois."
}
};
await _configService.SeedConfigs(configs);
}
}
And add it to the installer :
services.AddScoped<IConfigSeeder, JobConfigSeeder>();