Structr
  • Welcome
  • Utilities
    • Abstractions
      • Check
      • Ensure
      • Money
      • HierarchyId
      • Providers
        • SequentialGuidProvider
      • Extensions
        • DateTime
        • Dictionary
        • DirectoryInfo
        • Enumerable
        • Enum
        • Expression
        • Int
        • Long
        • MemberInfo
        • Object
        • Queryable
        • ServiceCollection
        • String
        • Type
      • Helpers
        • AsyncHelper
        • BindHelper
      • JsonConverters
        • DateOnly
        • TimeOnly
        • StringNumber
    • Collections
      • AutoMapper extensions
    • IO
      • FileHelper
      • MimeTypeHelper
      • PathHelper
      • SequentialFileName
    • Configuration
      • Providers
        • JSON-file
        • XML-file
        • In-Memory
        • Consul
      • Get settings
      • Set settings
      • Customization
    • Email
      • Razor
    • Navigation
      • Menu
      • Breadcrumbs
    • Security
  • Domain
    • Domain
      • Entities
      • Value objects
  • Data Access
    • Entity Framework Core
    • Entity Framework 6
  • Use Cases
    • Operations
      • Filtering
      • Decoration
    • Notices
    • Validation
    • Specifications
    • Stateflows
      • StateMachine
      • Configurations
  • Presentation
    • ASP.NET Core
      • Client
      • Http
      • JavaScript
      • Json
      • Mvc
      • Referrer
      • Rewrite
      • Routing
      • TagHelpers
      • Validation
Powered by GitBook
On this page
  • Installation
  • Setup
  • Usage

Was this helpful?

Edit on GitHub
  1. Utilities

Configuration

PreviousSequentialFileNameNextProviders

Last updated 2 years ago

Was this helpful?

Structr.Configuration package is intended to simplify work with application settings via mapping to classes to provide strongly typed access to groups of related settings.

Installation

Configuration package is available on .

dotnet add package Structr.Configuration

Setup

Create settings class.

public class SmtpEmailSettings
{
    public string Host { get; set; }
    public int Port { get; set; }
}

Configuration services uses different providers to get source settings. For example: JSON and XML file, Database, Consul KV, or something else.

You can create custom settings provider:

public class CustomConfigurationProvider<TSettings> : SettingsProvider<TSettings>
    where TSettings : class, new()
{
    public CustomConfigurationProvider(SettingsProviderOptions options) 
        : base(options) 
    {}
    
    protected override TSettings LoadSettings()
    {
        /* Do some logic here */
    }

    protected override void UpdateSettings(TSettings settings)
    {
        /* Do some logic here */
    }

    protected override bool IsSettingsModified()
    {
        /* Do some logic here */
    }

    protected override void LogFirstAccess()
    { 
        /* Do some logic here */
    }
}

And then setup configuration services:

services.AddConfiguration()
    .AddProvider(new CustomConfigurationProvider<SmtpEmailSettings>(new SettingsProviderOptions()));

Usage

Or you can use one of implemented settings provider from .

Structr.Configuration provides separate services for the and settings.

Also you can the settings members with special attribute.

NuGet
list
get
set
customize