Coder Social home page Coder Social logo

fig's People

Contributors

gitter-badger avatar myty avatar rofr avatar ven0maus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fig's Issues

Implement Configuration swapping

Changing Settings.Environment should reload from SettingsDictionary into the cache and fire PropertyChanged for any properties that change de to the Environment change.

Change name of Environment to Configuration, make it readonly property
and provide a method to change it, such as SwitchConfiguration(string)

Implement command line args source

Look at the builder method UseCommandLine. Add a source that takes a string array and parses into key/values. Maybe use an optional prefix like the other providers? So the following should result in 2 key/value pairs:

"--CoffeeshopSettings.EspressoMachineEnabled=true"
"--CoffeeShopSettings.TimeBetweenRefills=00:10:00"

Do we want this format: "--key=value"
Or do we want two consecutive array slots: "--key" "value"
Maybe support both?

Prefix not respected when binding to POCO

Actual code:

var settingsBuilder = new SettingsBuilder().UseAppSettingsXml();
var settings = settingsBuilder.Build();
var serviceSettings = settings.Bind<ServiceSettings>(requireAll: true, prefix: "");

Exception:

System.Collections.Generic.KeyNotFoundException: ServiceSettings.SipEnabled
   at Fig.Settings.Get(Type propertyType, String propertyName, String key, Func`1 default)
   at Fig.Settings.Bind[T](T target, Boolean requireAll, String prefix)
   at Fig.Settings.Bind[T](Boolean requireAll, String prefix)

Notice the class name is included in the missing key: ServiceSettings.SipEnabled
This should not be the case when passing an empty string as prefix.

Add Report() method to settings

Returns a string with the current configuration and which source each property came from or if default was used. Useful for diagnostics or in the log during startup

SQL Provider

Provider that uses a relation database source,

Can't derive from Settings

There is no public or protected constructor making it impossible to declare a subclass. Test works because assembly:InternalsVisibleTo

Support nested types when using inheritance based binding

Binding to POCOs supports nested types, but binding for classes that inherit Settings do not. Ideally the binding behavior should be identical but the the implementations are separate and use entirely different approaches due to the how the actual values are kept in memory.

So we could either change the inheritance binding to have the same behavior or integrate so that both approaches use the same code.

Here is a nested type example:
ie:

class MySettings
{
    public MyNestedSettings MyNestedProperty{get;private set;}
}

class MyNestedSettings
{
    public bool WidgetFlag{get;set;}
}

Given the above classes the setting MySettings.MyNestedProperty.WidgetFlag=true will be bound to the corresponding path on objects of type MySettings

Tests for the ini file format

Write unit tests for the ini file format

key1=This is a string with spaces
[Section.A]
ScanInterval=00:25:00
#comment
[OtherSection]
key3=300

should yield these 3 keys:

  • key1
  • Section.A.ScanInterval
  • OtherSection.key3

Environment qualifiers in JSON files

The environment qualier is appended using a ':' as separator. This works in INI-files and XML files but perhaps not appSettings.json because ':' is used as a path separator in JSON. I think it could be put it inside the attribute name like this:

{
   "MySetting" : 42,
   "MySetting:PROD" : 43
}

So the question is: Does the above already work and is it a good approach? I think the colon inside the attribute might cause some confusion.

A simple unit test answer the 'does it work' question. One thing that does not work though, if we decide to go this path, is having the qualifier above a nested object. (see #22 )

{
    "MySetting:PROD" : {
      "a":1,
     "b":2
    }
} 

this would translate into keys:
MySetting:PROD.a
MySetting:PROD.b

It seems like a rewrite of each key where the qualifier is moved to the the end would do trick. Actually, we could use the rewrite hack for INI files (#22 again) and other hierarchical sources as a postprocessing step on the settings dictionaries.

Use a key from the current dictionary to select the Environment

Given the following key/value pairs, we want Config to be used to set the current configuration.

ENV=PROD
ServiceUrl=http://localhost:8080/
ServiceUrl:PROD=https://myserver.com/
ServiceUrl:TEST=https://test.myserver.com/

We could do this with code like this:

var settings = new SettingsBuilder()
   .UseAppSettingsJson()
   .Build<MySettings>();
settings.SetEnvironment(settings.Get("Config"));

but it would be elegant to do this directly on the builder, allowing the setting to take effect in subsequent steps, ie:

var settings = new SettingsBuilder()
   .UseCommandLine(),
   .UseEnvironmentVariables()
   .SetEnvironment("${ENV}")
   .UseAppSettingsJson()
   .Build<MySettings>();

Environment qualifier on INI file sections

The following should be equivalent:

[MySection:PROD]
mySetting1=a
mySetting2=b

[MySection:TEST]
mySetting1=c
mySetting2=d

[MySection]
mySetting1=e
mySetting2=f
[MySection]
mySetting1:PROD=a
mySetting2:PROD=b
mySetting1:TEST=c
mySetting2:TEST=d
mySetting1=e
mySetting2=f

Support for arrays

An array in JSON translates into keys with numeric indexes, ie:

"brokers" : ["10.0.0.1", "10.0.0.2"]

will translate into the key/value pairs:

brokers.0=10.0.0.1
brokers.1=10.0.0.2

When we retrieve we want to be able to convert to array, ie:

var brokers = settings.Get<string[]>("brokers");

and a typed settings class:

class MySettings
{
   public string[] Brokers => Get<string[]>();
}

Expose ExpandVariables on the Settings class

settings.ExpandVariables("this is ${KEY} fun") will replace the key if it exists and return a new string. This is on the settings dictionary class but expose it on the Settings class so the user can benefit as well

CI/CD

Get this thing on AppVeyor or Azure Devops or similar so we can build, run tests and push packages on commit to master

Should we have separate packages for different sources?

Or just shove it all into a single project/package.

Currently, the AppSettingsXml source is in a separate project (and separate nuget package).
The reason is to minimize dependencies in the core package. In this case System.Configuration is the additional dependency.

All the other sources are in the core project: ini, json,env vars, command line. The json source uses the new System.Json so to follow the pattern this should have gone to a separate project as well.

What's your opinion here @myty ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.