Skip to content

Categorization of Data

Patrick edited this page May 11, 2018 · 7 revisions

The Configuration.EntityFramework provider supports the following categorization of data

1. Application

Configuration data can be associated with a particular application. When accessing settings via the .NET Core Configuration System, you can nominate to only retrieve settings for the current application.

2. Section

The Configuration Section allows settings to be grouped based on a common responsibility such as 'connectionStrings'. A section may also represent a complex type which has been serialized into a Json formatted string.

3. Aspect

In addition to 'Application' and 'Section' you can now categorize data based on 'Aspect'. An aspect represents a cross-cutting concern within an application such as Culture related strings. If you're using the Configuration database to store such data, it should be returned via the IStringLocalizer and not the ConfigurationProvider. While .NET Core comes with a IStringLocalizer for ResourceFiles, [Configuration.EntityFramework.Localization[(https://github.com/thinkabouthub/Configuration.EntityFramework.Localization/wiki) provides a custom IStringLocalizer called EFStringLocalizer which will retrieve Culture related strings from the Configuration Database.

So that the ConfigurationProvider does not retrieve data related to the localization aspect, by default, it will only return data where the Aspect is set to 'settings'.

Likewise, the EFStringLocalizer will only retrieve string values where the Aspect is set to 'localization'.

In Summary

  • By default, the [Configuration.EntityFramework] (https://www.nuget.org/packages?q=configuration.entityframework) provider will retrieve data where the Aspect is set to 'settings'.
  • The EFStringLocalizer located in Configuration.EntityFramework.Localization will retrieve string values where the Aspect is set to 'localization'.

Example 1

Define application settings

Sample Configuration.Section table

ApplicationName Aspect Section
PayrollWebAPI Application appSettings
PayrollWebAPI Application connectionStrings

Example 2

Define localized strings for Australia and France compatible with EFStringLocalizer

Sample Configuration.Section table

ApplicationName Aspect Section
PayrollWebAPI Localization en-AU
PayrollWebAPI Localization fr-FR

4. Discriminator

With the Configuration.EntityFramework provider, data can be categorized based on Application, Section and Aspect. However, if greater granularity is required then the Discriminator field can be used. With the Discriminator field, a configuration section can be categorized via a collection of Key-Value pairs defined using a Json formatted string.

Example 1

Segment appSettings for UserA and UserB

Sample Configuration.Section table

ApplicationName Aspect Section Discriminator
PayrollWebAPI Application appSettings {"Username":"UserA"}
PayrollWebAPI Application appSettings {"Username":"UserB"}

Example 2

Segment appSettings related to Test Environment for UserA and UserB

Sample Configuration.Section table

ApplicationName Aspect Section Discriminator
PayrollWebAPI Application appSettings {"Environment":"Testing", "Username":"UserA"}
PayrollWebAPI Application appSettings {"Environment":"Testing", "Username":"UserB"}

5. Tenant

The Configuration.EntityFramework provider now allows for the segmentation of settings based on a Tenant Identifier.