I'd like to get a value from my json configuration file before dependency injection is configured / before I call "Build()" on my service collection.
If I want to configure services differently depending on a value in my json configuration file, how would I do that?
Another way to phrase this is how do I get a configuration value from an IConfigurationRoot implementation?
In this code, how would I set the value of "useService1" depending on a value in my configuration file?
    class Program
    {
        static void Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json")
                .Build();
            var serviceCollection = new ServiceCollection();
            var useService1 = true; // how do I get a value from my configuration file here?
            if (useService1)
                serviceCollection.AddSingleton<IMyService>(new Service1());
            else
                serviceCollection.AddSingleton<IMyService>(new Service1());
            var serviceProvider = serviceCollection.BuildServiceProvider();
            var myService = serviceProvider.GetService<IMyService>();
            myService.DoWork();
        }
        interface IMyService
        {
            void DoWork();
        }
        class Service1 : IMyService
        {
            public void DoWork()
            {
                Console.WriteLine("1 doing work");
            }
        }
        class Service2 : IMyService
        {
            public void DoWork()
            {
                Console.WriteLine("2 doing work");
            }
        }
    }
				
                        
I'm able to get nested appsettings.json configuration values using a semicolon to specify nested values.
appsettings.json: