Skip to main content

Persistence Settings

These are Endatix API settings (Endatix:Persistence). They pick the database provider, connection strings, and migration behavior.

Configuring the Database Provider

The easiest way to specify which database provider Endatix should use is through the configuration:

"Endatix": {
"Persistence": {
"Provider": "PostgreSql" // Or "SqlServer"
}
}

Usage Examples

1. Automatic Configuration with Defaults

The simplest way to configure persistence with defaults:

// Automatically selects the provider from configuration
builder.Host.ConfigureEndatix();

2. Direct Provider Selection with Full Custom Configuration

Complete control over persistence configuration:

// Full custom configuration
builder.Host.ConfigureEndatix(endatix => {
endatix.WithPersistence(persistence => persistence
.UseSqlServer<AppDbContext>(options => {
options.ConnectionString = "Server=myserver;Database=mydb;Trusted_Connection=True;";
options.EnableSensitiveDataLogging = true;
options.CommandTimeout = 60;
options.MaxRetryCount = 5;
})
.EnableAutoMigrations()
.EnableSampleDataSeeding());
});

3. Hybrid Approach - Defaults Plus Customization

Start with defaults and customize only what you need:

// Hybrid approach
builder.Host.ConfigureEndatixWithDefaults(endatix => {
endatix.WithPersistence(persistence => {
// Override the connection string
persistence.UseSqlServer<AppDbContext>(options => {
options.ConnectionString = "your_custom_connection_string";
});

// Enable auto migrations
persistence.EnableAutoMigrations();
});
});

Convenience Methods

For scenarios where you only need to configure the database context without other customizations:

// Use the convenience method for SQL Server
builder.Host.ConfigureEndatix(endatix =>
endatix.UseSqlServer<AppDbContext>());

// Use the convenience method for PostgreSQL
builder.Host.ConfigureEndatix(endatix =>
endatix.UsePostgreSql<AppDbContext>());

Available Settings

SettingDescriptionDefault Value
Endatix:Persistence:ProviderThe database provider to use (SqlServer or PostgreSql)SqlServer
ConnectionStrings:DefaultConnectionThe default database connection stringNone
ConnectionStrings:DbProviderThe database provider to use (SqlServer or PostgreSql)SqlServer

Provider-Specific Options

Each database provider supports additional configuration options:

SQL Server Options

services.AddEndatix(configuration)
.UseSqlServer<AppDbContext>(options => {
options.ConnectionString = "your_connection_string";
options.MigrationsAssembly = "Your.Migrations.Assembly";
options.CommandTimeout = 30;
options.MaxRetryCount = 5;
options.MaxRetryDelay = 30;
options.EnableSensitiveDataLogging = false;
options.EnableDetailedErrors = false;
});

PostgreSQL Options

services.AddEndatix(configuration)
.UsePostgreSql<AppDbContext>(options => {
options.ConnectionString = "your_connection_string";
options.MigrationsAssembly = "Your.Migrations.Assembly";
options.CommandTimeout = 30;
options.MaxRetryCount = 5;
options.MaxRetryDelay = 30;
options.EnableSensitiveDataLogging = false;
options.EnableDetailedErrors = false;
});

Combining with Other Settings

You can combine persistence configuration with other Endatix features using the builder pattern:

services.AddEndatix(configuration)
.UseSqlServer<AppDbContext>()
.EnableAutoMigrations()
.EnableSampleDataSeeding()
.Api.AddSwagger().Build()
.Security.UseJwtAuthentication().Build();
Note

Database connection strings should be stored securely using secrets management in production environments.