aloneguid / config

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

add read-only option to ConfigurationBuilder #154

Open fafa3711 opened 12 months ago

fafa3711 commented 12 months ago

It would be handy to be able to specify if a built config is read-only, even though the underlying store is read-write. Background: I'm using Config.Net with JSON files to provide configuration for a library that needs a good number of static configured values. Of course I can just not provide a set accessor, but that is not what I'm after. I use Autofac DI to inject configurations into the various parts of the application and it works great, by registering the interface with a lambda in Autofac:

builder.Register(c =>
        {
            var configBuilder = new ConfigurationBuilder<ICoreConfig>();
            configBuilder.UseJsonFile(Path.Combine(path, "CoreConfig.json"));
            return configBuilder.Build();
        }).SingleInstance();

For command line utilities, I would like to selectively change (set) parts of the ICoreConfig, but not write out the changed config back to JSON. Right now, if I modify any values, they are persisted back to the original store.

I'd be happy to do this myself and file a PR if this something to fit into the concept of the library, but would probably have some feedback on the best way to go about it.