aloneguid / config

⚙ Config.Net - the easiest configuration framework for .NET developers. No BS.
MIT License
641 stars 85 forks source link

Overriding Or fallback support #88

Closed feitzi closed 4 years ago

feitzi commented 5 years ago

I am currently evaluating some configuration libraries. This library looks pretty good to me :) But I am wondering why you do not support fallback scenarios. I want to use a configuration structure like this:

server1.json overrides prod.json and prod.json overrides default.json. Naturally, this works only if you are in prod environment and on a host with name server1

Does config.net support something like this?

aloneguid commented 5 years ago

Thanks @feitzi for a good feedback (contribution will be even better :) ). Yes you can totally do that today with config.net. For instance you can do something like this:

IMySettings settings = new ConfigurationBuilder<IMySettings>()
   .UseJsonFile("config.default.json")
   .UseJsonFile("config.prod.json") //replace with config.etc.json
   .Build();

and so on. It will try to read the values in the order of declaration.

golavr commented 5 years ago

@feitzi you can use the appsettings.json similar to ASP.NET configuration. Handling appsettings.json with environment override file appsettings.{Environment}.json based on "APP_ENV" environment variable.

See Mapping to appsettings.json file for more information.