Example #1
0
        private static void RunForAppConfig()
        {
            // Manual configuration creation sample
            Console.WriteLine(Environment.NewLine + "**************** Manual sample");
            MainAppConfiguration configuration = new MainAppConfiguration();

            DumpConfiguration(configuration);

            // Using Autofac sample
            Console.WriteLine("**************** Autofac sample");
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterModule <ConsoleAppAutofacModule>();
            IContainer container = builder.Build();

            configuration = container.Resolve <MainAppConfiguration>();
            DumpConfiguration(configuration);

            // Manual configuration creation sample with short properties mapping
            Console.WriteLine(Environment.NewLine + "**************** Manual sample (long name mapping)");
            MainAppConfigurationLongPropertyName configurationLongPropertyName = new MainAppConfigurationLongPropertyName();

            DumpConfiguration(configurationLongPropertyName);

            // Using Autofac sample with short properties mapping
            Console.WriteLine(Environment.NewLine + "**************** Autofac sample (long name mapping)");
            configurationLongPropertyName = container.Resolve <MainAppConfigurationLongPropertyName>();
            DumpConfiguration(configurationLongPropertyName);

            // Manual configuration creation sample with custom properties mapping
            Console.WriteLine(Environment.NewLine + "**************** Manual sample (custom mapping)");
            CustomSettingNameConfiguration customSettingNameConfiguration = new CustomSettingNameConfiguration();

            DumpConfiguration(customSettingNameConfiguration);

            // Using Autofac sample with custom properties mapping
            Console.WriteLine(Environment.NewLine + "**************** Autofac sample (custom mapping)");
            customSettingNameConfiguration = container.Resolve <CustomSettingNameConfiguration>();
            DumpConfiguration(customSettingNameConfiguration);

            // Lazy initialization to prefent loading the settings in the constructor
            Console.WriteLine(Environment.NewLine + "**************** Lazy initialization");
            Lazy <MainAppConfiguration> lazyConfiguration = new Lazy <MainAppConfiguration>();

            DumpConfiguration(lazyConfiguration.Value);
        }
Example #2
0
        private static void DumpConfiguration(MainAppConfiguration configuration)
        {
            Console.WriteLine("AppVersion: " + configuration.AppVersion);
            Console.WriteLine("ComplexDetails.DisplayName: " + configuration.ComplexDetails.DisplayName);
            Console.WriteLine("ComplexDetails.Expiration: " + configuration.ComplexDetails.Expiration);
            Console.WriteLine("ComplexDetails.SomeDetails.Id: " + configuration.ComplexDetails.SomeDetails.Id);
            Console.WriteLine("ComplexDetails.SomeDetails.Name: " + configuration.ComplexDetails.SomeDetails.Name);
            Console.WriteLine("ComplexDetails.SomeDetails.Elapsed: " + configuration.ComplexDetails.SomeDetails.Elapsed);

            string json = JsonConvert.SerializeObject(configuration.ComplexDetails);

            Console.WriteLine("ComplexDetails JSON: " + json);

            Console.WriteLine("Enumerable INT setting: " + string.Join("#", configuration.IntegerValues));

            Console.WriteLine("Preprocessed: " + configuration.PreprocessedSetting);
        }