Configuration
Serenity integrates with the built-in Configuration system of ASP.NET Core.
We also prefer the Options
pattern where possible, which provides an abstraction of
configuration retrieval, and from its storage location. This is achieved using the dependency injection pattern.
The configuration for a typical Serene / StartSharp application resides in the appsettings.json
file
by default but it is possible to move some parts or all of it to a database, cloud, or any other location.
Here is a sample of configuration classes that are using options pattern:
assembly | class |
---|---|
Serenity.Net.Entity | ConnectionStringOptions |
Serenity.Net.Services | UploadSettings |
Serenity.Net.Web | CssBundlingOptions |
Serenity.Net.Web | ScriptBundlingOptions |
As we are using the Options
pattern, all these configuration options should be bound to their relevant sections via Configure
calls in Startup.cs
:
services.Configure<ConnectionStringOptions>(
Configuration.GetSection(ConnectionStringOptions.SectionKey));
services.Configure<CssBundlingOptions>(
Configuration.GetSection(CssBundlingOptions.SectionKey));
services.Configure<LocalTextPackages>(
Configuration.GetSection(LocalTextPackages.SectionKey));
services.Configure<ScriptBundlingOptions>(
Configuration.GetSection(ScriptBundlingOptions.SectionKey));
services.Configure<UploadSettings>(
Configuration.GetSection(UploadSettings.SectionKey));
services.Configure<Serenity.Extensions.EnvironmentSettings>(
Configuration.GetSection(Serenity.Extensions.EnvironmentSettings.SectionKey));
We provide the default SectionKey
for each configuration option as a constant in the class declaration:
public class ConnectionStringOptions : Dictionary<string, ConnectionStringEntry>,
IOptions<ConnectionStringOptions>
{
/// <summary>
/// Default sectionkey for ConnectionStringOptions
/// </summary>
public const string SectionKey = "Data";
//...
}
See the documents below for more information about ASP.NET Core configuration and options pattern: