Handling of application configuration storage and management across multiple instances.
Servers the configurations to the various clients
Represents a collection of associated configuration. The configuration set contains meta data and information on validating the configuration, all of which can be declared via a fluent api. Currently support configuration classes with primative properties.
Represents a collection of config items that can be used on their own or referenced by other configs. Option set may be internal to config server or from an external provider
Store for the configurations. Currently support:
- In Memory store
- File store
- Azure Blob storage
Provides configurators a way of configuring associated client configuration through a simple web interface with meta data and validation. Access through configserverpath/Manager
Client used by application to retrieve configuration. Local and HttpClients available. Configuration can be retrieved by injecting IConfigServer. Currently will have issues if multiple config of the same type are expected.
Adding ConfigServer and configuration sets to service collection:
public void ConfigureServices(IServiceCollection services)
{
services.AddConfigServer()
.UseConfigSet<SampleConfigSet>()
.UseInMemoryProvider();
//...
Adding ConfigServer to OWIN pipeline:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.Map("/Config", configSrv => configSrv.UseConfigServer(new ConfigServerOptions()));
public class SampleConfigSet : ConfigurationSet<SampleConfigSet>
{
public OptionSet<Option> OptionFromProvider { get; set; }
public OptionSet<OptionFromConfigSet> Options { get; set; }
public Config<SampleConfig> SampleConfig { get; set; }
protected override void OnModelCreation(ConfigurationSetModelBuilder<SampleConfigSet> modelBuilder)
{
modelBuilder.Options(s => s.Options, o => o.Id, o => o.Description, "Options", "Options for sample config");
modelBuilder.Options(s => s.OptionFromProvider, o => o.Id, o => o.Description, (IOptionProvider provider) => provider.GetOptions());
var configBuilder = modelBuilder.Config(x=> x.SampleConfig);
configBuilder.Property(p => p.IsLlamaFarmer).WithDisplayName("Is Llama farmer?").WithDescription("Is this a Llama farmer");
configBuilder.Property(p => p.Decimal).WithDisplayName("Value").WithDescription("Is a value in decimal");
configBuilder.Property(p => p.LlamaCapacity).WithDisplayName("Llama capacity")
.WithDescription("Is the capacity of llama")
.WithMinValue(0)
.WithMaxValue(50);
configBuilder.Property(p => p.StartDate).WithDisplayName("Start date")
.WithMinValue(new DateTime(2013, 10, 10));
configBuilder.Property(p => p.Name).WithMaxLength(250);
configBuilder.PropertyWithOption(p => p.Option, (SampleConfigSet set) => set.OptionFromProvider)
.WithDescription("Is a selected option");
}
}
Adding local client to ConfigServer:
services.AddConfigServer()
.UseConfigSet<SampleConfigSet>()
.UseInMemoryProvider()
.UseLocalConfigServerClient(clientId)
.WithConfig<SampleConfig>();
Adding remote client to application
services.AddConfigServerClient(new ConfigServerClientOptions
{
ConfigServer = "http://localhost:58201/Config"
})
.WithClientId("6A302E7D-05E9-4188-9612-4A2920E5C1AE")
.WithConfig<SampleConfig>()
.WithCollectionConfig<OptionFromConfigSet>();;
services.AddConfigServerClient(new ConfigServerClientOptions
{
ConfigServer = "http://localhost:58201/Config"
})
.WithClientId("6A302E7D-05E9-4188-9612-4A2920E5C1AE")
.WithConfig<SampleConfig>()
.WithCollectionConfig<OptionFromConfigSet>();
Consuming configuration
public async Task<IActionResult> Index()
{
var config = await configProvider.GetConfigAsync<SampleConfig>();
var options = await configProvider.GetCollectionConfigAsync<OptionFromConfigSet>();
return View(new ConfigViewModel { Config = config, Options = options });
}
Includes self hosted ConfigServer and configurator along with local client to consume the configuration.
Includes httpClient that gets configuration from ConfigServer.Sample.mvc