LiteOrm reads a LiteOrm configuration section, then wires up services, DAO types, and optional dialect overrides during startup.
appsettings.json example{
"LiteOrm": {
"Default": "DefaultConnection",
"DataSources": [
{
"Name": "DefaultConnection",
"ConnectionString": "Server=localhost;Database=TestDb;User Id=root;Password=123456;",
"Provider": "MySqlConnector.MySqlConnection, MySqlConnector",
"SqlBuilder": null,
"KeepAliveDuration": "00:10:00",
"PoolSize": 16,
"MaxPoolSize": 100,
"ParamCountLimit": 2000,
"SyncTable": false,
"ReadOnlyConfigs": []
}
]
}
}
| Setting | Purpose |
|---|---|
Default |
Default data source name |
DataSources[].Name |
Identifier referenced by [Table(DataSource = "...")] |
Provider |
Fully qualified connection type name |
SqlBuilder |
Optional custom dialect type |
KeepAliveDuration |
Connection keep-alive duration |
PoolSize / MaxPoolSize |
Connection pool sizing |
ParamCountLimit |
Parameter-count cap for one SQL statement |
ReadOnlyConfigs |
Read replicas for read/write splitting |
var host = Host.CreateDefaultBuilder(args)
.RegisterLiteOrm()
.Build();
var builder = WebApplication.CreateBuilder(args);
builder.Host.RegisterLiteOrm();
builder.Host.RegisterLiteOrm(options =>
{
options.RegisterScope = true;
options.Assemblies = new[] { typeof(MyService).Assembly };
options.RegisterSqlBuilder("DefaultConnection", new MySqlBuilder());
});
LiteOrm runtime logging is built on Microsoft.Extensions.Logging. Service-call logs, exception logs, and slow-query logs follow whatever providers the host application has configured.
var builder = WebApplication.CreateBuilder(args);
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Host.RegisterLiteOrm();
options.LoggerFactory is forbuilder.Host.RegisterLiteOrm(options =>
{
options.LoggerFactory = LoggerFactory.Create(logging =>
{
logging.AddConsole();
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Information);
});
});
ILoggerFactory handles normal service invocation logsoptions.LoggerFactory is mainly for framework registration and assembly-scan outputFor attribute usage and diagnostics guidance, see Logging and Diagnostics.
[Table(DataSource = "...")] to bind an entity to a non-default source.ReadOnlyConfigs when reads can safely go to replicas.SqlBuilder when a provider needs database-version-specific SQL.Provider contain?Use the full connection type name, for example System.Data.SqlClient.SqlConnection, System.Data.SqlClient.
SqlBuilder?Usually when paging syntax, function SQL, or legacy database behavior differs from LiteOrm’s default dialect.